-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(SideNavItems): unrecognized prop warning for 'isSideNavExpanded' #4627
fix(SideNavItems): unrecognized prop warning for 'isSideNavExpanded' #4627
Conversation
Hi there would you mind changing your commit to prop commit convention. TYIA |
Deploy preview for the-carbon-components ready! Built with commit e18f9db https://deploy-preview-4627--the-carbon-components.netlify.com |
Deploy preview for carbon-components-react ready! Built with commit e18f9db https://deploy-preview-4627--carbon-components-react.netlify.com |
Deploy preview for carbon-elements ready! Built with commit e18f9db |
Deploy preview for carbon-elements ready! Built with commit 53938a4 |
Deploy preview for carbon-components-react ready! Built with commit 53938a4 https://deploy-preview-4627--carbon-components-react.netlify.com |
Deploy preview for the-carbon-components ready! Built with commit 53938a4 https://deploy-preview-4627--the-carbon-components.netlify.com |
@@ -19,6 +20,12 @@ const SideNavItems = ({ | |||
}) => { | |||
const className = cx([`${prefix}--side-nav__items`], customClassName); | |||
const childrenWithExpandedState = React.Children.map(children, child => { | |||
if ( | |||
typeof child.type === 'string' || | |||
(child.type === SideNavLink && child.props.element === 'a') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi 👋 thank you for another try - Would you try investigating more wrt what components get isSideNavExpanded
prop as a child of <SideNavItems>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sound good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From all the components that have isSideNavExpanded
property (SideNavHeader
, SideNavFooter
, SideNavLink
, SideNavMenu
, UIShell/Link
) only SideNavLink
and UIShell/Link
are ones that could potentially pass it to DOM element and produce the warning, I will add another check for UIShell/Link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is element
property used consistently through out the project? If that is the case I could just check if that property value is an a
tag and that would handle more scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not certain, and I imagine it easily gets no longer the case even if it's the case now. Also, such prop doesn't seem to be in use. BTW wondering why you thought of adding such check...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, looks like this is already fixed
@dariusbakunas just to clarify, is the use-case here to support elements other than |
@@ -19,6 +21,13 @@ const SideNavItems = ({ | |||
}) => { | |||
const className = cx([`${prefix}--side-nav__items`], customClassName); | |||
const childrenWithExpandedState = React.Children.map(children, child => { | |||
if ( | |||
typeof child.type === 'string' || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the typeof
the type always string? Maybe should just be child.type
.
This sort of type inference is generally super fragile. What happens if someone uses a custom SideNavItem
or otherwise wraps the item?
This whole boolean expression is really difficult to parse what the intended behavior is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, type is string only if child is DOM element, not React Component, so if you put <a>
tag directly as a child
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, ultimately the issue lies in children that wrap DOM elements, like for example UIShell/Link
, that component just passes through all props to React.createElement function.. thus my initial pr had a fix on Link element, I don't think that there is a way to determine at this level that your child is just passing all props to DOM element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dariusbakunas just to clarify, is the use-case here to support elements other than
SideNavItem
inSideNavItems
?
This is to stop React does not recognize the
isSideNavExpanded prop on a DOM element
warning message when child is SideNavLink with property element
set to a
Fixes #3970
Fixes console warning for SideNavItems component:
Changelog
Changed
Avoid passing
isSideNavExpanded
property to DOM elements or SideNavLink that wraps anchor tagTesting / Reviewing
Launch storybook with
yarn storybook
and go tohttp://localhost:9000/?path=/story/ui-shell--sidenav-w-large-side-nav-items
and observe that console warning about unknown prop is no longer visible