-
Notifications
You must be signed in to change notification settings - Fork 671
[Action Bar] Fix warning with menu items #6935
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
Changes from 5 commits
efd81b8
071c37e
4ba828b
2bb06dc
685fc99
414854d
c24d35a
4402b7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': patch | ||
| --- | ||
|
|
||
| Fix overflow calculations of more menu button in action bar |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,16 +217,10 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop | |
| if (menuItem.type === ActionList.Divider) { | ||
| return <ActionList.Divider key={index} /> | ||
| } else { | ||
| const { | ||
| children: menuItemChildren, | ||
| onClick, | ||
| icon: Icon, | ||
| 'aria-label': ariaLabel, | ||
| disabled, | ||
| } = menuItem.props | ||
| const {onClick, icon: Icon, 'aria-label': ariaLabel, disabled} = menuItem.props | ||
| return ( | ||
| <ActionList.Item | ||
| key={menuItemChildren} | ||
| key={ariaLabel} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not make it related to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The index could change if the window is resized. For example, if the toolbar overflowed at the "Insert Link" button, then it would be the first index in the menu and the key would be "0". When the window is resized smaller to overflow the next button, then the "Insert Code" button would be the first index now with a key of "0". While each key is still unique, this can cause odd issues if the keys match different components when rerendering in React |
||
| // eslint-disable-next-line primer-react/prefer-action-list-item-onselect | ||
| onClick={(event: React.MouseEvent<HTMLLIElement, MouseEvent>) => { | ||
| closeOverlay() | ||
|
|
||
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.
Using
ariaLabelas the key could cause issues if multiple menu items have the same aria-label or if aria-label is undefined. Consider usingindexor a combination ofindexandariaLabelto ensure uniqueness.