primitives icon indicating copy to clipboard operation
primitives copied to clipboard

[Dialog][DropdownMenu] Possible regression in auto focus behaviour when opening a dialog from a dropdown

Open Michael-Nielsen opened this issue 2 years ago • 1 comments

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

Michael-Nielsen avatar Aug 12 '22 11:08 Michael-Nielsen

I believe I am having the same issue.

djalmaaraujo avatar Aug 25 '22 17:08 djalmaaraujo

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?

ConnorHome avatar Oct 09 '23 14:10 ConnorHome

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.

benoitgrelard avatar Mar 06 '24 14:03 benoitgrelard