Fix nested NavItems

Currently, a NavItem having more than one child will throw an error. This is due to the `children` property of `NavItem` being passed as the first argument to `React.cloneElement`, which expects a single element. The existing tests are only verifying the case where the `NavItem` has only one child.

This commit maps over `children` and calls `React.cloneElement` on each of them.
This commit is contained in:
Yasa Akbulut
2020-02-19 14:17:57 +01:00
committed by GitHub
parent 29b4e4f9a3
commit 7cde0fd01e
@@ -100,7 +100,7 @@ class NavItem extends Component {
// Automatically expand nested nav if one of the child elements is active
const isChildActive = React.Children.toArray(children).some(c => NavItem.isActive(c.props.href, c.props.exact));
const isExpanded = expanded || isChildActive;
const selfAwareChildren = children && React.cloneElement(children, { child: true });
const selfAwareChildren = children && React.Children.map(children, c => React.cloneElement(c, { child: true }));
let iconElement;