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(SideNavItems): unrecognized prop warning for 'isSideNavExpanded' #4627

Closed
wants to merge 11 commits into from
Closed

fix(SideNavItems): unrecognized prop warning for 'isSideNavExpanded' #4627

wants to merge 11 commits into from

Conversation

dariusbakunas
Copy link

@dariusbakunas dariusbakunas commented Nov 8, 2019

Fixes #3970

Fixes console warning for SideNavItems component:

 React does not recognize the `isSideNavExpanded` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `issidenavexpanded` instead. If you accidentally passed it from a parent component, remove it from the DOM element

Changelog

Changed

  • SideNavItems

Avoid passing isSideNavExpanded property to DOM elements or SideNavLink that wraps anchor tag

Testing / Reviewing

Launch storybook with yarn storybook and go to http://localhost:9000/?path=/story/ui-shell--sidenav-w-large-side-nav-items and observe that console warning about unknown prop is no longer visible

@dariusbakunas dariusbakunas requested a review from a team as a code owner November 8, 2019 18:16
@ghost ghost requested review from aledavila and vpicone November 8, 2019 18:16
@aledavila
Copy link
Contributor

Hi there would you mind changing your commit to prop commit convention. TYIA

@dariusbakunas dariusbakunas changed the title Fix nav item props fix(Link): unrecognized prop warning for 'isSideNavExpanded' #4124 Nov 8, 2019
@dariusbakunas dariusbakunas changed the title fix(Link): unrecognized prop warning for 'isSideNavExpanded' #4124 fix(SideNavItems): unrecognized prop warning for 'isSideNavExpanded' #4124 Nov 8, 2019
@dariusbakunas dariusbakunas changed the title fix(SideNavItems): unrecognized prop warning for 'isSideNavExpanded' #4124 fix(SideNavItems): unrecognized prop warning for 'isSideNavExpanded' Nov 8, 2019
@netlify
Copy link

netlify bot commented Nov 8, 2019

Deploy preview for the-carbon-components ready!

Built with commit e18f9db

https://deploy-preview-4627--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Nov 8, 2019

Deploy preview for carbon-components-react ready!

Built with commit e18f9db

https://deploy-preview-4627--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Nov 8, 2019

Deploy preview for carbon-elements ready!

Built with commit e18f9db

https://deploy-preview-4627--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Nov 8, 2019

Deploy preview for carbon-elements ready!

Built with commit 53938a4

https://deploy-preview-4627--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Nov 8, 2019

Deploy preview for carbon-components-react ready!

Built with commit 53938a4

https://deploy-preview-4627--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Nov 8, 2019

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')
Copy link
Contributor

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>?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sound good

Copy link
Author

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

Copy link
Author

@dariusbakunas dariusbakunas Nov 11, 2019

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

Copy link
Contributor

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...?

Copy link
Author

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

@joshblack
Copy link
Contributor

@dariusbakunas just to clarify, is the use-case here to support elements other than SideNavItem in SideNavItems?

@@ -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' ||
Copy link
Contributor

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.

Copy link
Author

@dariusbakunas dariusbakunas Nov 11, 2019

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

Copy link
Author

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

Copy link
Author

@dariusbakunas dariusbakunas left a 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 in SideNavItems?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React does not recognize the isSideNavExpanded prop on a DOM element
5 participants