Add active anchors to ActionBar actions - #8320
Conversation
🦋 Changeset detectedLatest commit: 997b0b6 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 |
|
There was a problem hiding this comment.
Pull request overview
Adds a dedicated “active anchor” ref for ActionBar action triggers and updates overlay anchoring/focus behavior so overlays can track and react to the currently visible trigger as actions move between the inline bar and overflow menu.
Changes:
- Added
activeAnchorReftoActionBar.ButtonandActionBar.IconButton, publishing either the inline button element or the overflow (“More items”) button depending on overflow state. - Updated
AnchoredOverlay’srenderAnchorcallback to receive a reactiveanchorRef(2nd argument) and re-position while open when the physical anchor element changes. - Updated focus-return behavior to focus the current
returnFocusReftarget at cleanup time, and expanded tests/docs/React Compiler coverage accordingly.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/SelectPanel/SelectPanel.tsx | Passes through the new (props, anchorRef) renderAnchor signature so SelectPanel anchors can use reactive refs. |
| packages/react/src/hooks/useOpenAndCloseFocus.ts | Focuses the current returnFocusRef.current on cleanup to support moving targets while open. |
| packages/react/src/hooks/tests/useOpenAndCloseFocus.test.tsx | Adds coverage for return-focus target changes before effect cleanup. |
| packages/react/src/deprecated/ActionMenu.tsx | Updates deprecated ActionMenu wrapper to forward (props, anchorRef) to its renderAnchor. |
| packages/react/src/AnchoredOverlay/AnchoredOverlay.types.test.tsx | Updates type test to use new renderAnchor signature and attach the provided ref. |
| packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx | Introduces reactive anchor element tracking and re-positioning when the anchor DOM node changes. |
| packages/react/src/AnchoredOverlay/AnchoredOverlay.test.tsx | Adds a test ensuring repositioning when the rendered anchor is replaced while open. |
| packages/react/src/AnchoredOverlay/AnchoredOverlay.docs.json | Documents the updated renderAnchor signature and the reactive ref behavior. |
| packages/react/src/ActionBar/ActionBar.tsx | Implements activeAnchorRef plumbing and makes overflow menu state controlled to coordinate selection/close behavior. |
| packages/react/src/ActionBar/ActionBar.test.tsx | Adds tests covering activeAnchorRef, overflow transitions, and overlay focus/position behavior via SelectPanel. |
| packages/react/src/ActionBar/ActionBar.docs.json | Documents the new activeAnchorRef prop on ActionBar buttons. |
| packages/react/script/react-compiler.mjs | Removes ActionBar from the React Compiler unsupported list. |
| .changeset/actionbar-active-anchor.md | Adds a minor changeset for the new ActionBar/AnchoredOverlay API surface. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 13/13 changed files
- Comments generated: 1
- Review effort level: Lite
|
Integration test results from github/github-ui PR:
CI check runs linting, type checking, and unit tests. Check the workflow logs for specific failures. Need help? If you believe this failure is unrelated to your changes, please reach out to the Primer team for assistance. |
Closes #
Adds a dedicated active-anchor ref to ActionBar actions so consumers can track the physical button that currently represents an action as it moves between the inline bar and overflow menu. Open overlays now react to anchor replacement for positioning and focus return.
Motivation
github/github-ui#30256 delegates ListView action clipping, overflow rendering, and focus management to Primer React instead of maintaining a separate measurement engine. Some actions render stateful overlays such as
SelectPanel; those overlays must remain mounted as the action moves into or out of overflow so filter state is preserved.During that transition, the physical trigger changes between the inline action button and ActionBar's More items button. The normal forwarded
refmust continue to identify the action's own button, while overlay positioning and focus return need the currently visible trigger.activeAnchorRefprovides that second contract directly, replacing a consumer-side bridge that otherwise has to coordinate multiple refs and discover the overflow button through DOM selectors.Changelog
New
activeAnchorReftoActionBar.ButtonandActionBar.IconButton.AnchoredOverlay'srenderAnchorcallback.Changed
Removed
Rollout strategy
The new APIs are additive and covered by a minor changeset.
Testing & Reviewing
npm test -- ActionBar/ActionBar.test.tsx AnchoredOverlay/AnchoredOverlay.test.tsx hooks/__tests__/useOpenAndCloseFocus.test.tsxnpm run type-check --workspace packages/reactnpm run lint:react-compiler --workspace packages/reactnpx eslintfor changed TypeScript filesgit diff --checkReview the ActionBar tests for inline/overflow transitions, pointer and keyboard activation, disabled/grouped actions, callback and object refs, focus restoration, and Button/IconButton parity. Review the AnchoredOverlay test for live repositioning when the rendered anchor changes.