Closed tobiasSchaathun closed 3 months ago
I figured it out, leaving it here if anyone is interested i the answer in the future....
You can add an "onKeyDown" to the Command itself and use event.preventDefault to achieve this :)
Hi, I am running into the same issue. The problem is that with event.preventDefault
the input will also not handle the event.
What I want is the default functionality: Home goes to beginning of the input text and End to the end of the text. Unfortunately this seems not possible to achieve looking at the code: https://github.com/pacocoursey/cmdk/blob/92344c58a63b995f6eb149245c56ea548540dd18/cmdk/src/index.tsx#L571-L575
This workaround worked for me: stop the keydown event from propagating from the input.
<Command.Input
[...]
onKeyDown={(event) => {
switch (event.key) {
// NOTE: prevents unwanted cmdk behaviour
case 'Home':
case 'End':
event.stopPropagation()
break
}
}}
/>
@kevin-lonestone Awesome workaround. Works perfectly. Thanks a lot! :tada:
Hello, is there a way to disable that the "Home" and "End" jump to the first and last index of the item list? I want to use it to do this in the input and wish to disable this behaviour for the items themselves.