Skip to content

Prevent default behaviour of closing dropdown menu on pressing ctrl+enter #1645

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

Open
RashmiRamdas opened this issue Apr 15, 2025 · 0 comments

Comments

@RashmiRamdas
Copy link

RashmiRamdas commented Apr 15, 2025

Hi, I need to prevent a dropdown menu from closing when Ctrl+Enter is pressed while a dropdown item is focused. However, the menu should close when Enter is pressed, which is working as expected. Can someone provide some input on this?

I tried something like this, passing onKeyDown to getItemProps. But, onKeyDown is not getting triggered at all.

            {...getItemProps({
                key: item.value && item.value.toString(),
                item,
                index,
                onKeyDown: (e) => {
                    console.log("press on item")
                    if(e.ctrlKey || (e.ctrlKey && e.key === "Enter")) {
                        e.nativeEvent.stopImmediatePropagation();
                    }
                },
                onClick: (e) => {
                    e.nativeEvent.stopImmediatePropagation();
                },
            })}
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

1 participant