-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Navigation component: Fix item handling onClick twice #33286
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
Navigation component: Fix item handling onClick twice #33286
Conversation
|
Size Change: +16 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
Addison-Stavlo
left a comment
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 tested this out and it works well!
The changes look safe, but it would be good to get another set of 👀
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.
Testing
Requirements
- SET_PAGE action is only fired once
Browsers
- Chrome
| }; | ||
| const icon = isRTL() ? chevronLeft : chevronRight; | ||
| const baseProps = isText | ||
| const baseProps = children ? props : { ...props, onClick: undefined }; |
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 might be missing something, but if isText is false and children is true, couldn't we still have 2 onClick handlers registered?
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 don't think so 🤔 We don't apply the props on the children automatically. So in this case NavigationItemBase will get an onClick˛handler but nothing else. You can still put an onClick handler on your children in the userland code. But that would mean you are using the component wrong.
Correct way is to add your onClick to the NavigationItem:
<NavigationItem onClick={() => alert('Hello')}>
<div>There is only one event click handler</div>
</NavigationItem>Wrong way
<NavigationItem onClick={() => alert('Hello')}>
<div onClick={() => alert('Hello children!')}>There is only one event click handler</div>
</NavigationItem>Note, when we have children then the itemProps is not used at all.
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.
Note, when we have children then the itemProps is not used at all
Ahhh I think this is what's confusing me. Why use isText at all if we can infer component state from the presence or absence of children?
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.
We need to make sure ItemUI is acting as a text in case of isText, otherwise we turn it into a button.
isText = true = We pass rest props, so it's up to the user to add extra props
isText = false = We default to a clickable navigation button
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.
Oh I see what's happening now 🤦 . I'm tracking. Thanks for the explanation @david-szabo97!
0101d9c to
142c6df
Compare
Description
Both
NavigationItemBaseandItemUIregistered anonClickevent listener. This PR tries to ensure that it is only registered once on the right component. (ItemUI)When
childrenis specified then we leave the choice of addingonClickto theNavigationItemBaseto the consumer. In other case, we use the defaultItemUIcomponent which means we need to remove theonClickfrom the props passed toNavigationItemBaseto avoid double event handling.How has this been tested?
core/edit-siteinstance)Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.jsfiles for terms that need renaming or removal).