diff --git a/frontend/packages/shared/components/layout/NavItem.js b/frontend/packages/shared/components/layout/NavItem.js
index b6d47ab9f6..92656e57c2 100644
--- a/frontend/packages/shared/components/layout/NavItem.js
+++ b/frontend/packages/shared/components/layout/NavItem.js
@@ -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;
diff --git a/frontend/packages/shared/components/layout/NavItem.test.js b/frontend/packages/shared/components/layout/NavItem.test.js
index 997b765a12..9c892e2812 100644
--- a/frontend/packages/shared/components/layout/NavItem.test.js
+++ b/frontend/packages/shared/components/layout/NavItem.test.js
@@ -15,11 +15,6 @@ const minProps = {
href: '/mocked',
};
-const minChildProps = {
- title: 'A child title',
- href: '/child',
-};
-
describe('', () => {
it('renders without exploding', () => {
const rendered = render(wrapInThemedTestApp());
@@ -59,7 +54,8 @@ describe('', () => {
const { getByText, getByTestId } = render(
wrapInThemedTestApp(
-
+
+
,
),
);
@@ -71,13 +67,15 @@ describe('', () => {
const { getByText, getByTestId, queryByText } = render(
wrapInThemedTestApp(
-
+
+
,
),
);
expect(queryByText('A child link')).not.toBeInTheDocument();
fireEvent.click(getByTestId('expand-toggle'));
- expect(getByText('A child title')).toBeInTheDocument();
+ expect(getByText('Child 1 title')).toBeInTheDocument();
+ expect(getByText('Child 2 title')).toBeInTheDocument();
});
it('shows nested navigation automatically if the child is active', () => {
@@ -85,11 +83,12 @@ describe('', () => {
const { getByText } = render(
wrapInThemedTestApp(
-
+
+
,
),
);
expect(getByText('A link title')).toBeInTheDocument();
- expect(getByText('A child title')).toBeInTheDocument();
+ expect(getByText('Child 1 title')).toBeInTheDocument();
});
});