From 635c1448525e7d3e15f9769c47e16ae1fe312585 Mon Sep 17 00:00:00 2001 From: emyarod Date: Fri, 19 Mar 2021 14:51:20 -0500 Subject: [PATCH 1/2] fix(UIShell): avoid spreading `isSideNavExpanded` to non Carbon elements --- packages/react/src/components/UIShell/SideNav.js | 8 +++++++- packages/react/src/components/UIShell/SideNavItems.js | 10 +++++++++- packages/react/src/components/UIShell/_utils.js | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 packages/react/src/components/UIShell/_utils.js diff --git a/packages/react/src/components/UIShell/SideNav.js b/packages/react/src/components/UIShell/SideNav.js index 12a88afe2057..df66e88cb090 100644 --- a/packages/react/src/components/UIShell/SideNav.js +++ b/packages/react/src/components/UIShell/SideNav.js @@ -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'; @@ -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, + } + : {}), }); }); } diff --git a/packages/react/src/components/UIShell/SideNavItems.js b/packages/react/src/components/UIShell/SideNavItems.js index b8998e308f89..465c929c8a17 100644 --- a/packages/react/src/components/UIShell/SideNavItems.js +++ b/packages/react/src/components/UIShell/SideNavItems.js @@ -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; @@ -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 ; diff --git a/packages/react/src/components/UIShell/_utils.js b/packages/react/src/components/UIShell/_utils.js new file mode 100644 index 000000000000..8953a0806a96 --- /dev/null +++ b/packages/react/src/components/UIShell/_utils.js @@ -0,0 +1,6 @@ +export const CARBON_SIDENAV_ITEMS = [ + 'SideNavFooter', + 'SideNavHeader', + 'SideNavItems', + 'SideNavMenu', +]; From 427055330646fa56f6231559f6cc445f3d199518 Mon Sep 17 00:00:00 2001 From: emyarod Date: Fri, 19 Mar 2021 14:51:41 -0500 Subject: [PATCH 2/2] refactor(SideNavLink): remove unneeded destructuring --- packages/react/src/components/UIShell/SideNavLink.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/react/src/components/UIShell/SideNavLink.js b/packages/react/src/components/UIShell/SideNavLink.js index 2d0471f47f05..9fcd9e7f2330 100644 --- a/packages/react/src/components/UIShell/SideNavLink.js +++ b/packages/react/src/components/UIShell/SideNavLink.js @@ -23,8 +23,6 @@ const SideNavLink = React.forwardRef(function SideNavLink( renderIcon: IconElement, isActive, large, - // eslint-disable-next-line no-unused-vars - isSideNavExpanded, ...rest }, ref