Closed envex closed 7 years ago
Interesting. We currently call preventDefault
and stopPropagation
to indicate that the keymap system has "consumed" the event by transforming it into the specified command, but I don't actually have a clear picture of exactly what would go wrong if we didn't do that. It's been a long time since that decision was made.
Could you explain the specifics of your situation? Do you have a proposal for how it would work?
The example in this situation is I have a searchable item component. In that component is an input
and a select
dropdown (set to multiple so it acts/looks like a list).
Natively, once the select
is focused, you can use the arrow keys to navigate through the list. You can see that functionality here: http://jsbin.com/geremameme/edit?html,output
I've setup a custom up (and down) key event so that if the input is focused, pressing the down arrow would focus the select
.
With the key-map attaching the down
event, the native down
event is blocked and only the key-map down
is fired.
Ideally it would be nice if I could either:
preventDefault()
// Badly coded example
window.addEventListener('up-event', (event) => {
// Do something
event.bubble();
});
Could you map the up arrow to the special native!
directive or use the .native-key-bindings
class on your component and do your own event handling?
Yeah, I'm just handling it natively for now. I was just curious if there was a way to use keymap for that event/situation.
You can also call abortKeyBinding
on the emitted command event to tell the keymap system that even though the binding matched and emitted a command, you still want to continue as if the key binding didn't match. This wouldn't prevent other bindings further up in the document from matching the event however. Does that address your issue?
Interesting. That may be the key. Let me test it out and I'll get back to you.
Thanks!
That did the trick, thanks!
This is setup in an electron app
(v1.6.7)
with react(v15.1)
.I have a
select
input that is set to multiple and I've setup an event in my component.My event is setup like so in
KeymapManager
:When I have this event setup, the native up/down arrow events are blocked for the select input. Ideally, I'd like to be able to fire my
up-event
and have it bubble up so the native event is also fired.Note: If this is against the guidelines, or irrelevant, please close.