Skip to content

[ESR-2405]-Restore focus to trigger button when pressing Escape - #6542

Open
seany-amp wants to merge 3 commits into
mainfrom
esr-2405-export-button-lost-focus
Open

[ESR-2405]-Restore focus to trigger button when pressing Escape#6542
seany-amp wants to merge 3 commits into
mainfrom
esr-2405-export-button-lost-focus

Conversation

@seany-amp

@seany-amp seany-amp commented Apr 2, 2026

Copy link
Copy Markdown

Why

When pressing Escape to close a Menu dropdown (e.g., the Export button in TitleBlock), focus was being lost instead of returning to the trigger button. This is an accessibility
issue as keyboard users lose their place in the page.

Related ticket: Export button lost focus on hitting the Esc key

What

The root cause was that the returnFocus callback in MenuDropdown was calling focus() on referenceElement, which is a wrapper

used for Popper positioning - not the actual
focusable button.

Changes:

  • Added a buttonRef to track the button's imperative handle ({ focus: () => void })
  • Pass this ref through StatelessMenu → MenuDropdown
  • Use buttonRef.current.focus() in the returnFocus callback, with fallback to referenceElement for backwards compatibility
  • Added mergeRefs utility in Menu to preserve any existing ref on the button (e.g., AddFiltersMenu uses its own ref)
  • Added test case verifying focus returns to button on Escape

Before: Focus lost when pressing Escape

Screen.Recording.2026-03-25.at.5.16.42.pm.1.mov

After: Focus returns to the trigger button

Screen.Recording.2026-04-02.at.2.00.13.pm.mov

@changeset-bot

changeset-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 150aa32

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kaizen/components Patch

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

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

✨ Here is your branch preview! ✨

Last updated for commit 150aa32: fix: lint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant