Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
arrow-key-navigation
Advanced tools
arrow-key-navigation
is a simple utility to add left/right focus navigation to a web app. It's
designed for KaiOS apps but also available for any browser.
The basic idea is to make the ← and → keys act similar to Tab and Shift+Tab, i.e. to change focus between focusable elements in the DOM. Since the ↑ and ↓ keys typically scroll the page in KaiOS, this is usually all you need to add basic KaiOS accessibility to an existing web app.
It will also listen for the Enter key for certain special cases like checkbox/radio buttons. contenteditable
and Shadow DOM are also supported.
npm install --save arrow-key-navigation
Or browse unpkg.com for a list of build files.
import * as arrowKeyNavigation from 'arrow-key-navigation'
arrowKeyNavigation.register() // start listening for key inputs
arrowKeyNavigation.unregister() // stop listening
To build an accessible dialog, you need to "trap" focus inside of the dialog, i.e. make it so focus cannot escape the dialog while it is active. To accomplish this, you can set a "focus trap test" which takes an element as input and returns truthy/falsy to indicate that the element is a focus trap (e.g. the modal dialog root):
arrowKeyNavigation.setFocusTrapTest(element => {
return element.classList.contains('my-dialog-class')
})
If you don't call setFocusTrapTest()
, then arrow-key-navigation
will assume that there are no focus traps
in your app.
You can choose to install this module only in KaiOS environments using logic like the following:
if (/KAIOS/.test(navigator.userAgent)) {
import('arrow-key-navigation').then(arrowKeyNavigation => {
arrowKeyNavigation.register()
})
}
npm run build
npm run lint
npm run lint:fix
npm test
npm run cover
The index.html
and manifest.webapp
files are designed for a quick-and-dirty KaiOS app test.
Run npm run build
and then install the root directory as a packaged KaiOS app to test it.
FAQs
Add left/right key navigation to a KaiOS app or web app
We found that arrow-key-navigation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.