-
Notifications
You must be signed in to change notification settings - Fork 639
[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
Conversation
🦋 Changeset detectedLatest commit: 4402b7a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks! |
3710770
to
4ba828b
Compare
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.
Pull Request Overview
This PR fixes a React warning about missing unique "key" props in ActionBar menu items by changing the key from menuItemChildren
(which was undefined) to ariaLabel
. It also enhances the ActionBar Comment Box story with header right content.
- Fixed React key prop warning by using
ariaLabel
instead of undefinedmenuItemChildren
for menu item keys - Added header right section to the Comment Box story with Write/Preview buttons
- Updated e2e test expectations to match the new button count in the story
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/react/src/ActionBar/ActionBar.tsx | Fixed key prop by using ariaLabel and removed unused menuItemChildren destructuring |
packages/react/src/ActionBar/ActionBar.examples.stories.tsx | Added header right section with Write/Preview buttons |
packages/react/src/ActionBar/ActionBar.examples.stories.module.css | Added CSS styles for the new header right section |
e2e/components/drafts/ActionBar.test.ts | Updated test expectations to match new button counts |
.changeset/smart-hornets-happen.md | Added changeset for patch release |
return ( | ||
<ActionList.Item | ||
key={menuItemChildren} | ||
key={ariaLabel} |
Copilot
AI
Oct 1, 2025
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 ariaLabel
as the key could cause issues if multiple menu items have the same aria-label or if aria-label is undefined. Consider using index
or a combination of index
and ariaLabel
to ensure uniqueness.
key={ariaLabel} | |
key={`${index}-${ariaLabel ?? 'item'}`} |
Copilot uses AI. Check for mistakes.
return ( | ||
<ActionList.Item | ||
key={menuItemChildren} | ||
key={ariaLabel} |
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.
Why not make it related to index
? Would index be changing between renders somehow?
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.
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
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/3796 |
🔴 ci completed with status |
Related to https://github.com/github/github-ui/pull/3638#discussion_r2395195779
Fixed
Each child in a list should have a unique "key" prop
warning when mapping the menu itemsChangelog
Added
Changed
key
to useariaLabel
instead of undefinedmenuItemChildren
Rollout strategy
Testing & Reviewing
Merge checklist