質問編集履歴
3
指摘を受けて試した結果を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -215,3 +215,139 @@
|
|
215
215
|
|
216
216
|
|
217
217
|
子の`this.props.isSelected`に親の変更を反映させるためにはどうすれば良いのでしょうか?初歩的な質問ですがよろしくおねがいします。
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
---
|
222
|
+
|
223
|
+
# 追記
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
maisumakunさんの指摘を受けてList要素を直接配列に入れるのではなく、要素の持つ情報のみを配列に入れ、List要素自体は`map`を使って生成するように変更しましたが、未だに親要素の`isSeletected`は更新されるのに小要素のものは更新されないという現象が続いています。
|
228
|
+
|
229
|
+
```javascript
|
230
|
+
|
231
|
+
class SideBar extends React.Component {
|
232
|
+
|
233
|
+
constructor(props) {
|
234
|
+
|
235
|
+
super(props);
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
this.state = {
|
240
|
+
|
241
|
+
folders: [],
|
242
|
+
|
243
|
+
isSelected: false,
|
244
|
+
|
245
|
+
};
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
this.createFolder = this.createFolder.bind(this);
|
250
|
+
|
251
|
+
this.changeBackColor = this.changeBackColor.bind(this);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
changeBackColor(message) {
|
258
|
+
|
259
|
+
this.setState({isSelected: !this.state.isSelected});
|
260
|
+
|
261
|
+
console.log(this.state.isSelected);
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
// このメソッドを書き換えた
|
268
|
+
|
269
|
+
createFolder() {
|
270
|
+
|
271
|
+
this.setState({
|
272
|
+
|
273
|
+
folders: this.state.folders.concat(
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
key: this.state.numFolders,
|
278
|
+
|
279
|
+
isSelected: this.state.isSelected,
|
280
|
+
|
281
|
+
deleteFunc: this.deleteFolder,
|
282
|
+
|
283
|
+
changeBackColor: this.changeBackColor
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
)
|
288
|
+
|
289
|
+
});
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
render() {
|
298
|
+
|
299
|
+
const { classes } = this.props;
|
300
|
+
|
301
|
+
const folders = this.state.folders;
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
return (
|
306
|
+
|
307
|
+
<Drawer
|
308
|
+
|
309
|
+
variant="permanent"
|
310
|
+
|
311
|
+
classes={{
|
312
|
+
|
313
|
+
paper: sidebarStatus // hayashi: what is the paper?
|
314
|
+
|
315
|
+
}}
|
316
|
+
|
317
|
+
open={this.state.isOpen}
|
318
|
+
|
319
|
+
>
|
320
|
+
|
321
|
+
<div className={classes.allFolders}>
|
322
|
+
|
323
|
+
// map を使って子を生成するようにした
|
324
|
+
|
325
|
+
{ folders.map((folder) =>
|
326
|
+
|
327
|
+
<PaperFolder
|
328
|
+
|
329
|
+
key={folder.key}
|
330
|
+
|
331
|
+
isSelected={folder.isSelected}
|
332
|
+
|
333
|
+
deleteFunc={folder.deleteFunc}
|
334
|
+
|
335
|
+
changeBackColor={folder.changeBackColor}
|
336
|
+
|
337
|
+
/>
|
338
|
+
|
339
|
+
)}
|
340
|
+
|
341
|
+
</div>
|
342
|
+
|
343
|
+
</Drawer>
|
344
|
+
|
345
|
+
)
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
```
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -168,6 +168,36 @@
|
|
168
168
|
|
169
169
|
}
|
170
170
|
|
171
|
+
|
172
|
+
|
173
|
+
const styles = theme => ({
|
174
|
+
|
175
|
+
folder: {
|
176
|
+
|
177
|
+
paddingBottom: 0,
|
178
|
+
|
179
|
+
paddingTop: 5,
|
180
|
+
|
181
|
+
},
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
selected: {
|
186
|
+
|
187
|
+
backgroundColor: "#e6e6e6",
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
});
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
export default withStyles(styles)(PaperFolder);
|
198
|
+
|
199
|
+
|
200
|
+
|
171
201
|
```
|
172
202
|
|
173
203
|
|
1
質問の不十分な点を補充
test
CHANGED
File without changes
|
test
CHANGED
@@ -118,11 +118,47 @@
|
|
118
118
|
|
119
119
|
render() {
|
120
120
|
|
121
|
+
const { classes } = this.props;
|
122
|
+
|
123
|
+
const filenameText = <ListItemText primary={this.state.name} onDoubleClick={this.openTextbox}/>;
|
124
|
+
|
125
|
+
const inputText = <TextField
|
126
|
+
|
127
|
+
value={this.state.value}
|
128
|
+
|
129
|
+
onChange={this.handleValue}
|
130
|
+
|
131
|
+
onKeyDown={this.rename}
|
132
|
+
|
133
|
+
autoFocus
|
134
|
+
|
135
|
+
/>;
|
136
|
+
|
137
|
+
const folderStyle = clsx({
|
138
|
+
|
139
|
+
[classes.folder]: true,
|
140
|
+
|
141
|
+
[classes.selected]: this.props.isSelected,
|
142
|
+
|
143
|
+
});
|
144
|
+
|
145
|
+
|
146
|
+
|
121
147
|
return (
|
122
148
|
|
123
149
|
<List className={classes.folder} onClick={this.select}>
|
124
150
|
|
151
|
+
<ListItem
|
152
|
+
|
153
|
+
className={folderStyle}
|
154
|
+
|
155
|
+
onClick={this.handleListClick}
|
156
|
+
|
157
|
+
>
|
158
|
+
|
125
159
|
// ...
|
160
|
+
|
161
|
+
</ListItem>
|
126
162
|
|
127
163
|
</List>
|
128
164
|
|