Socket
Socket
Sign inDemoInstall

accessible-navigation

Package Overview
Dependencies
6
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    accessible-navigation

A pub/sub observer that handles keyboard navigation for tabs, accordions and menus.


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Install size
4.88 MB
Created
Weekly downloads
 

Readme

Source

Aria Keyboard A11y

A pub/sub observer that handles keyboard navigation for tabs, accordions and menus.

This solution bundles the appropriate arrow navigation keys. It relies on browser native support for keyboard Tab, Shift+Tab as well as Enter and Spacebar behavior from HTML <button /> elements.

Goal

The drive behind the concept was to make the browser work smarter not harder. Leveraging everything we get natively for free from the browser and then add only the support that is missing. The solution abstracts away the functionality from the component to simplify usage.

Requirements

This solution currently recommends and supports native HTML button elements to get full access to the appropriate supported keyboard events.a

TODO: Confirm tag support

KeyboardNav

A pub/sub class observer that monitors the elements provided to handle the keyboard events.

Methods
  • subscribe - A method that takes a unique label and element arguments to construct elements that are subscribed to the navigation events.
  • unsubscribe - A method that takes the unique label as an argument and unsubscribes from the item being observed.
  • update - A method that takes two arguments the event and label arguments. These trigger the navigation event. Recommended to be used with onKeyDown.
  • view - A method used for console logging the elements being observed.

Use with React

import { createKeyboardNav, KeyboardNav } from 'aria-keyboard-a11y'
const tabs = KeyboardNav('horizontal')
const useKeyboardNav = createKeyboardNav(tabs)

function Tab({ label, title, setActiveTabs, isSelected = false, index = 0 }) {
  function handleKeyDown(event) {
    tabs.update(event, label)
  }
  const refs = useKeyboardNav(label)

  return (
    <>
      <button
        ref={refs}
        className={`tab ${isSelected ? 'isSelected' : ''}`}
        type="button"
        onClick={handleClick}
        role="tab"
        aria-selected={isSelected}
        aria-controls={`tabpanel-${index}`}
        id={`tab-${index}`}
        onKeyDown={handleKeyDown}
      >
        {title}
      </button>
    </>
  )
}

Usage with native html

FAQs

Last updated on 23 Feb 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc