downshift icon indicating copy to clipboard operation
downshift copied to clipboard

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

Open RashmiRamdas opened this issue 9 months ago • 1 comments

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();
                },
            })}

RashmiRamdas avatar Apr 15 '25 12:04 RashmiRamdas

Hey @RashmiRamdas I believe you need to stop the downshift behaviour when your keys are pressed. Will this do?

silviuaavram avatar Jun 02 '25 07:06 silviuaavram