No way to do preventDefault
Hi, Is there a way to turn on preventDefault for a keypress (or all keypresses)?
I know there's been some discussion about preventDefault at: https://github.com/elm-lang/virtual-dom/issues/18 , but that discussion seems to be mainly about key presses that are sent to an Input component, etc.
Specifically, when I press Tab, it's handled by Keyboard.Extra, but Chrome also focuses elements on the page (including going to the URL bar); this messes up subsequent key presses being handled the right way.
Can you add another (js) listener to prevent it?
document.documentElement.addEventListener('keydown', function (e) {
if (e.which == 9) { // 9 is tab
e.preventDefault();
}
}, false);
Ah, that works perfectly! I guess it's unfortunate that we need to go to JS to do it, but it doesn't involve the boilerplate of ports, so it's an easy workaround. Thanks!
Awesome, are you OK to close this @egauderman ?
Yeah, it's not possible to preventDefault on document in Elm. I suppose I could add a note in the readme, but then I'd want to point out that you shouldn't disable the accessibility features built into browsers...
I think it would be good to make a note in the readme -- I think it'll save people some time in the future. My issue is solved, so I'm fine if you want to close the issue.