Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arrowtab

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arrowtab

Use arrow keys to "tab" between focusable elements

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50
increased by6.38%
Maintainers
0
Weekly downloads
 
Created
Source

ArrowTab

ArrowTab allows you to navigate a webpage using the arrow keys, automatically selecting the nearest focusable element. This enables fast and efficient keyboard-only navigation across the page.

ArrowTab is particularly useful for business applications, where power users need to prioritize high productivity.

Instead of hitting Tab repeatedly, you can simply use the arrow keys to indicate the direction and jump to the next input, button, or link you want to select.

ArrowTab's default settings work well, but they are not always a plug-and-play solution. It helps if you build your app with ArrowTab in mind. For example, aligning your focusable elements into a grid and considering the placement of your navigation. The idea is to integrate ArrowTab into your app from the beginning, not to add it as an afterthought.

Input Behavior Changes

ArrowTab slightly modifies the behavior of some input elements to enhance keyboard navigation. For example, number inputs will not change their value when using the up and down arrow keys; instead, the focus will move to the element above or below.

To revert to the native behavior, press Shift + Arrow Key.

Installation

pnpm:

pnpm install arrowtab

yarn:

yarn add arrowtab

npm:

npm install arrowtab

Usage

Vanilla JS:

import { initArrowTab } from 'arrowtab'

initArrowTab()

React:

'use client'

import { useEffect } from 'react'
import { initArrowTab } from 'arrowtab'

export const ArrowTab = () => {
  useEffect(() => {
    const { cleanup } = initArrowTab()

    return () => {
      cleanup()
    }
  }, [])

  return null
}

Cleanup

If you want to remove the ArrowTab event listener, you can call the cleanup function. This is useful if you use ArrowTab in a useEffect hook.

const { cleanup } = initArrowTab()

cleanup()

Options

You can pass options to the initArrowTab function. For example:

initArrowTab({
  debug: true,
  autoDetectHistory: true,
})

debug

default: false

If debug is set to true, ArrowTab will log debug information to the console. It also enables the visual debug mode. To activate the visual debug mode, press Ctrl + Arrow Key. For example, Ctrl + Arrow Down will highlight all the focusable elements.

Here is an example:

Visual debug mode example

Blue indicates the current element. Green indicates focusable elements that are within reach, and red indicates those that are not within reach.

The numbers represent the order of the focusable elements. The numbers in parentheses represent the order of the focusable elements that are within reach. Lower numbers are closer to the current element.

If you click on a focusable element, debug information will be logged to the console.

To deactivate the visual debug mode, press Esc.

autoDetectHistory

default: false

If true, ArrowTab will automatically detect dialogs and refocuses the last focused element when the dialog closes.

data-arrowtab

You can control the behavior of ArrowTab by adding a data-arrowtab attribute to any element. Separate the keywords with a space. For example: <div data-arrowtab="disable-left disable-right">

Here are the available keywords:

disable, disable-${key}

Sometimes your components are listening to arrow keys themselves. In that case, you can disable ArrowTab for that element by adding the disable attribute.

If you only want to disable a specific key, then use: disable-left, disable-right, disable-up, disable-down.

Development

pnpm dev

A demo page will open in your browser at http://localhost:8080.

If you want to use the library in your app, you can use the following code:

import { initArrowTab } from 'http://localhost:8080/dist/index.js'

initArrowTab()

Or as a script tag:

<script type="module">
  import { initArrowTab } from 'http://localhost:8080/dist/index.js'

  initArrowTab()
</script>

Keywords

FAQs

Package last updated on 15 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc