Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(UIShell): avoid spreading isSideNavExpanded to non Carbon elements #8135

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/react/src/components/UIShell/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { settings } from 'carbon-components';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { AriaLabelPropType } from '../../prop-types/AriaPropTypes';
import { CARBON_SIDENAV_ITEMS } from './_utils';
// TO-DO: comment back in when footer is added for rails
// import SideNavFooter from './SideNavFooter';

Expand Down Expand Up @@ -87,8 +88,13 @@ const SideNav = React.forwardRef(function SideNav(props, ref) {
let currentExpansionState = controlled
? expandedViaHoverState || expanded
: expanded;
// avoid spreading `isSideNavExpanded` to non-Carbon UI Shell children
return React.cloneElement(child, {
isSideNavExpanded: currentExpansionState,
...(CARBON_SIDENAV_ITEMS.includes(child.type?.displayName)
? {
isSideNavExpanded: currentExpansionState,
}
: {}),
});
});
}
Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/components/UIShell/SideNavItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { settings } from 'carbon-components';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { CARBON_SIDENAV_ITEMS } from './_utils';

const { prefix } = settings;

Expand All @@ -20,7 +21,14 @@ const SideNavItems = ({
const className = cx([`${prefix}--side-nav__items`], customClassName);
const childrenWithExpandedState = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
return React.cloneElement(child, { isSideNavExpanded });
// avoid spreading `isSideNavExpanded` to non-Carbon UI Shell children
return React.cloneElement(child, {
...(CARBON_SIDENAV_ITEMS.includes(child.type?.displayName)
? {
isSideNavExpanded,
}
: {}),
});
}
});
return <ul className={className}>{childrenWithExpandedState}</ul>;
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/components/UIShell/SideNavLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const SideNavLink = React.forwardRef(function SideNavLink(
renderIcon: IconElement,
isActive,
large,
// eslint-disable-next-line no-unused-vars
isSideNavExpanded,
...rest
},
ref
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/components/UIShell/_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const CARBON_SIDENAV_ITEMS = [
'SideNavFooter',
'SideNavHeader',
'SideNavItems',
'SideNavMenu',
];