-
Notifications
You must be signed in to change notification settings - Fork 646
Added callback onActiveDescendantChanged prop to FilteredActionList #7277
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
base: main
Are you sure you want to change the base?
Added callback onActiveDescendantChanged prop to FilteredActionList #7277
Conversation
🦋 Changeset detectedLatest commit: 84d49c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the |
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 adds a new onActiveDescendantChanged callback prop to FilteredActionList, enabling consumers to react to keyboard navigation changes. This is particularly useful for virtualized lists that need to programmatically scroll items into view when navigating with the keyboard, since aria-activedescendant keeps focus on the input element rather than moving it to list items.
Key changes:
- Added
onActiveDescendantChangedcallback prop toFilteredActionListwith comprehensive JSDoc documentation - Updated the Virtualized story in SelectPanel to demonstrate scrolling items into view using the new callback
- Incremented package versions to 38.4.0 (minor bump)
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
packages/react/src/FilteredActionList/FilteredActionList.tsx |
Added new optional onActiveDescendantChanged callback prop that forwards active descendant changes from the internal focus zone, including updated useMemo dependencies |
packages/react/src/SelectPanel/SelectPanel.examples.stories.tsx |
Updated Virtualized story to use the new callback for scrolling virtualized items into view during keyboard navigation, refactored code structure |
.changeset/fruity-groups-brush.md |
Added changeset documenting the new callback prop as a minor version change |
package-lock.json |
Updated version references from 38.3.0 to 38.4.0 and styled-react from 1.0.1 to 1.0.2 across workspaces |
| '@primer/react': minor | ||
| --- | ||
|
|
||
| Added callback prop onActiveDescendantChanged to FilterActionList' |
Copilot
AI
Dec 5, 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.
Typo in changeset message: "FilterActionList" should be "FilteredActionList" (missing 'ed').
| Added callback prop onActiveDescendantChanged to FilterActionList' | |
| Added callback prop onActiveDescendantChanged to FilteredActionList |
| id: 'select-labels-panel-dialog', | ||
| }} | ||
| onActiveDescendantChanged={useCallback( | ||
| (newActivedescendant: HTMLElement | undefined) => { |
Copilot
AI
Dec 5, 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.
Parameter name has inconsistent casing: newActivedescendant should use camelCase as newActiveDescendant (capital 'D' in 'Descendant') to match the parameter names in the callback signature and TypeScript naming conventions.
| const index = newActivedescendant?.getAttribute('data-index') | ||
| const range = virtualizer.range | ||
| if (newActivedescendant === undefined) return |
Copilot
AI
Dec 5, 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.
Redundant check: The condition checks newActivedescendant === undefined on line 718 and returns early, making the null-safe optional chaining on line 720 (newActivedescendant?.getAttribute) unnecessary. After the early return, newActivedescendant is guaranteed to be defined. Consider using newActivedescendant.getAttribute('data-index') directly on line 720 for clearer logic.
| const index = newActivedescendant?.getAttribute('data-index') | |
| const range = virtualizer.range | |
| if (newActivedescendant === undefined) return | |
| if (newActivedescendant === undefined) return | |
| const index = newActivedescendant.getAttribute('data-index') | |
| const range = virtualizer.range |
Closes #
When using the
useVirtualizerhook to virtualize select panel items, keyboard navigation does not automatically scroll items into view. Although useVirtualizer provides a scrollToIndex function for handling navigation, this isn’t triggered with ariaActiveDescendant, since it keeps focus on the input element instead of moving it. To address this, we need to callvirtualizer.scrollToIndex(Number(newActiveDescendant.getAttribute('data-index')), { align: 'auto' })each time the active descendant changes, ensuring the newly highlighted item is visible during keyboard navigation. This can be accomplished if I can expose a onActiveDescendantChanged prop.Changelog
New
Changed
Removed
Rollout strategy
Testing & Reviewing
Merge checklist