Disable ArrowDown/ArrowUp key handlers when focusing input
See original GitHub issueSo, basically issue with any form I have on page using LocomotiveScroll.
When I am focused in any input, and I press arrow keys (for example to pick something from autocomplete), the page scrolls.
Is there any way to disable this behavior?
I tried the following, which kind of works, but I really do not like the idea for hacking it by using setTimeout (element is my input wrapper that I am selecting elsewhere, locomotive is globally defined)
let keydownHandler = (e) => {
if(e.code === "ArrowDown" || e.code === "ArrowUp") {
locomotive.stop();
setTimeout(()=>{
locomotive.start();
},1);
}
}
element.querySelector("input").addEventListener("focus", () => {
document.addEventListener("keydown",keydownHandler,false);
});
element.querySelector("input").addEventListener("blur", () => {
document.removeEventListener("keydown",keydownHandler,false);
locomotive.start();
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Disable arrow key scrolling in users browser - Stack Overflow
Summary. Simply prevent the default browser action: window.addEventListener("keydown", function(e) { if(["Space","ArrowUp","ArrowDown","ArrowLeft" ...
Read more >Angular A11y: 5 Keyboard Listeners Tips - Better Programming
To open the options list in the dropdown, the user presses Enter after setting the focus in that field. Then they use arrow-down/arrow-up...
Read more >C Keyboard Shortcuts - Oracle Help Center
Enter key : Triggers an action when the cursor is in certain fields or when the focus is on a link or button....
Read more >Element: focusin event - Web APIs | MDN
The focusin event fires when an element has received focus, after the focus event. ... <form id="form"> <label>Some text: <input type="text" ...
Read more >FIS User Manual - UCSC Financial Affairs
Type or search for a Page name in the Search field, then key [enter]. ... most units do not receive the General Ledger,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you can disabled Autocomplete from form html by add autocomplete=“off” onto form element
let keydownHandler = (e) => { if(e.code === "ArrowDown" || e.code === "ArrowUp") { locomotive.update(); } }