mui / base-ui

Base UI is an open-source library of accessible, unstyled UI components for React.
https://mui.com/base-ui/
MIT License
231 stars 42 forks source link

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

Open vladmoroz opened 2 days ago

vladmoroz commented 2 days ago

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

atomiks commented 2 days ago

@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:

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.