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

[Dropdown Menu] Support for onOpenAutoFocus #3125

Closed
sekeidesign opened this issue Sep 18, 2024 · 3 comments
Closed

[Dropdown Menu] Support for onOpenAutoFocus #3125

sekeidesign opened this issue Sep 18, 2024 · 3 comments

Comments

@sekeidesign
Copy link

Feature request

Overview

We recently replaced our own Popover component to be built on top of react-dropdown-menu instead of react-popover since the two are almost identical, but the DropdownMenu also supports Submenus which is definitely something we want.

The migration was essentially free since both of these components share the vast majority of functionality and props, with the exception of onOpenAutoFocus.

We use onOpenAutoFocus to prevent the Popover from grabbing focus in our Combobox which then uses the Input trigger's onBlur event to close the Popover.

Example:

CleanShot.2024-09-18.at.14.33.53.mp4
import * as RadixPopover from '@radix-ui/react-popover'
...
<RadixPopover.Content 
    onOpenAutoFocus={event => {
        if (preventAutoFocus) {
            event.preventDefault()
        }
    }}
...
>

Compared with dropdown-menu

CleanShot.2024-09-18.at.14.36.57.mp4
import * as RadixPopover from '@radix-ui/react-dropdown-menu'
...
<RadixPopover.Content 
    // onOpenAutoFocus not supported!
...
>

Everything else is exactly the same and fully supported without any changes anywhere in our codebase.

Examples in other libraries

Radix already supports this in other "popover" style components:
https://www.radix-ui.com/primitives/docs/components/popover#content

Who does this impact? Who is this for?

It's a helpful event for managing focus that right now prevents us from using this component for our combobox.

@ilkiri23
Copy link

ilkiri23 commented Sep 24, 2024

We were faced with a similar problem. It'd be very useful to have an onOpenAutoFocus prop

@sekeidesign
Copy link
Author

We were faced with a similar problem. It'd be very useful to have an onOpenAutoFocus prop

I tried forking and taking a stab at it, but it started causing some intensely buggy behaviour. I suspect the reason the prop isn't there is because managing the focus is critical to how the dropdown menu functions :(

I'll close this and open a new PR for adding a Sub item to the Popover, which might be a better solution

@sekeidesign sekeidesign closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2024
@sekeidesign
Copy link
Author

Changed to this, since I think it may be a better solution
#3140

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

No branches or pull requests

2 participants