primitives
primitives copied to clipboard
[Dialog][DropdownMenu] Possible regression in auto focus behaviour when opening a dialog from a dropdown
Bug report
There appears to be a regression with the autofocus behaviour when opening a dialog from a dropdown. Previous suggested solutions found within Discord (thread here) worked fine in pre-1.0 solutions, i.e. 0.1.7
however when identical code is updated to use the most recent versions, the behaviour breaks.
Current Behavior
The input with the autoFocus
prop does not receive focus.
Expected behavior
The input receives focus.
Reproducible example
Codesandbox containing the original suggested solution using versions 0.1.7 and 0.1.6 of the Dialog and Dropdown primitive: https://codesandbox.io/s/dropdownmenu-dialog-forked-vvb95z?file=/src/App.js
Codesandbox containing identical code with recent versions 1.0.0 of both components: https://codesandbox.io/s/dropdownmenu-dialog-forked-hvg3ii?file=/src/App.js
Your environment
Software | Name(s) | Version |
---|---|---|
Radix Package(s) | @radix-ui/react-dialog @radix-ui/react-dropdown-menu |
1.0.0 |
I believe I am having the same issue.
I'm also experiencing this behaviour with @radix-ui/react-alert-dialog: 1.0.4
and @radix-ui/react-dropdown-menu: 2.0.5
. Has anyone figured out a workaround?
I don't think we ever had any code to handle elements with autoFocus
, the behaviour you see is correct, ie. the cancel button in an alert dialog should receive focus. If you want to override that, you can simply call event.preventDefault
in onOpenAutoFocus
.