Skip to content
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

[dialog] In Safari, focus isn't returned to the trigger when dialog is closed #618

Open
vladmoroz opened this issue Sep 16, 2024 · 1 comment
Assignees
Labels
browser: Safari component: dialog This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@vladmoroz
Copy link
Contributor

vladmoroz commented Sep 16, 2024

Steps to reproduce

Link to live example:
https://master--base-ui.netlify.app/components/react-dialog/

Current behavior

Focus is returned to the start of the document, apparently

Expected behavior

Focus is returned to the trigger

Context

No response

Your environment

Safari 17.6

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: safari, focus, return, trigger, close, dialog, modal

@vladmoroz vladmoroz added status: waiting for maintainer These issues haven't been looked at yet by a maintainer component: dialog This is the name of the generic UI component, not the React module! browser: Safari labels Sep 16, 2024
@atomiks
Copy link
Contributor

atomiks commented Sep 17, 2024

@michaldudak this problem is caused by Safari not focusing buttons on mousedown, so the previously focused element isn't the trigger.

When using useClick from Floating UI, this problem is solved, but custom event handlers won't work.

Possible solutions:

  • Swap to the useClick hook
  • Add the custom click mouse event to context.dataRef.current.openEvent (that's what the focus manager checks for)
  • Return focus manually for Safari

I don't think switching to useButton and rendering a <div> (which might take focus instead) will be reliable since they compose a native <button> tag in theory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser: Safari component: dialog This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
Status: Backlog
Development

No branches or pull requests

3 participants