question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable ArrowDown/ArrowUp key handlers when focusing input

See original GitHub issue

So, 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:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

5reactions
saidMounaimcommented, Mar 10, 2021

you can disabled Autocomplete from form html by add autocomplete=“off” onto form element

2reactions
saidMounaimcommented, Mar 11, 2021

let keydownHandler = (e) => { if(e.code === "ArrowDown" || e.code === "ArrowUp") { locomotive.update(); } }

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found