Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

Commit 81eef5d

Browse files
author
rdrgn
committed
update DatFolder to restore the renderChildren function
1 parent 5366c8d commit 81eef5d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

dev/src/react-dat-gui/components/DatFolder.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import React, { Component, cloneElement } from 'react';
22

33
import PropTypes from 'prop-types';
44
import cx from 'classnames';
@@ -23,9 +23,17 @@ export default class DatFolder extends Component {
2323
this.setState({ closed });
2424
}
2525

26+
renderChildren() {
27+
// Disable this rule to take title out of the props so nested folders can have unique titles.
28+
// eslint-disable-next-line no-unused-vars
29+
const { children, title, ...rest } = this.props;
30+
31+
return React.Children.map(children, child => cloneElement(child, {...rest}));
32+
}
33+
2634
render() {
2735
const { closed } = this.state;
28-
const { title, children } = this.props;
36+
const { title } = this.props;
2937

3038
return (
3139
<li className={cx('folder', { 'closed': closed })}>
@@ -34,7 +42,7 @@ export default class DatFolder extends Component {
3442
{title}
3543
</div>
3644
<ul>
37-
{children}
45+
{this.renderChildren()}
3846
</ul>
3947
</div>
4048
</li>

src/components/DatFolder.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import React, { Component, cloneElement } from 'react';
22

33
import PropTypes from 'prop-types';
44
import cx from 'classnames';
@@ -23,9 +23,17 @@ export default class DatFolder extends Component {
2323
this.setState({ closed });
2424
}
2525

26+
renderChildren() {
27+
// Disable this rule to take title out of the props so nested folders can have unique titles.
28+
// eslint-disable-next-line no-unused-vars
29+
const { children, title, ...rest } = this.props;
30+
31+
return React.Children.map(children, child => cloneElement(child, {...rest}));
32+
}
33+
2634
render() {
2735
const { closed } = this.state;
28-
const { title, children } = this.props;
36+
const { title } = this.props;
2937

3038
return (
3139
<li className={cx('folder', { 'closed': closed })}>
@@ -34,7 +42,7 @@ export default class DatFolder extends Component {
3442
{title}
3543
</div>
3644
<ul>
37-
{children}
45+
{this.renderChildren()}
3846
</ul>
3947
</div>
4048
</li>

0 commit comments

Comments
 (0)