Skip to content

fix: add a props to make the menu focus the trigger when closing #355

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

florianduros
Copy link
Member

@florianduros florianduros commented Jun 18, 2025

Due to #147

We want to have the focus to be back on the trigger when the menu closes.

Copy link

cloudflare-workers-and-pages bot commented Jun 18, 2025

Deploying compound-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8748045
Status: ✅  Deploy successful!
Preview URL: https://6bd3b04d.compound-web.pages.dev
Branch Preview URL: https://florianduros-focus-menu.compound-web.pages.dev

View logs

@florianduros florianduros marked this pull request as ready for review June 18, 2025 10:05
@florianduros florianduros requested a review from a team as a code owner June 18, 2025 10:05
@florianduros florianduros requested review from dbkr and robintown and removed request for a team June 18, 2025 10:05
@@ -123,9 +129,11 @@ export const Menu: FC<Props> = ({
align={align}
sideOffset={8}
onCloseAutoFocus={(event) => {
// https://www.radix-ui.com/primitives/docs/components/dropdown-menu#content => onCloseAutoFocus
// Prevent the default behavior of focusing the trigger when the menu closes
Copy link
Member

@t3chguy t3chguy Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning focus is the wai-aria specified behaviour, when would we want focusTriggerOnClose=false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was for the case of TAC: #147
Maybe it make more sense to put the props to true by default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the TAC is not accessible then, I just tried in EW and closing the tac resets my tab position to the start of the page which is very much a no-no. The tooltip showing again is a nit at best vs a major accessibility failure. Might want to special-case the focus return for keyboard accessibility vs pointer interaction if hiding the tooltip on close is important, or a way to not show the tooltip on menu close somehow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In succinct terms, I think focusTriggerOnClose is misled and needs to be forced to true generally, including for the TAC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll revert then #147

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as a safe interim solution changing it to not apply for keyboard interaction might be saner, to not regress the general UX, the more intricate solution can always come later

Copy link
Member Author

@florianduros florianduros Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm wrong but radix doesn't offer this kind of precision in its event. It is firing a custom event without info if it's from a keyboard or pointer interaction (for both escape or menu item selection)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's daft. radix-ui/primitives#2248 (comment) is the issue with a potential workaround

Copy link
Member Author

@florianduros florianduros Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the issue and I think it's different of our use case. We don't have a tooltip inside a popover but on the popover trigger. Stopping propagation makes the first row of the tac unfocused, the user can't interact with it.

I don't see any good solution where UX and a11y are ok. I'll remove the #147 to make the TAC accessible.

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.

2 participants