Socket
Socket
Sign inDemoInstall

@accessible/link

Package Overview
Dependencies
6
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @accessible/link

🅰 A component that adds aria attributes and keydown events to non-A elements in order to make them act like native links


Version published
Weekly downloads
115
increased by194.87%
Maintainers
1
Install size
124 kB
Created
Weekly downloads
 

Changelog

Source

2.0.0 (2020-07-08)

⚠ BREAKING CHANGES

  • The Link component is no longer the default export. It is a named export e.g. import {Link} from '@accessible/link'.

Features

  • add useA11yLink() hook (3bf0781)

Readme

Source

Bundlephobia Types Code coverage Build status NPM Version MIT License

npm i @accessible/link

A component that adds aria attributes and keydown events to non-A elements in order to make them act like native links.

Quick Start

Check out the example on CodeSandbox

import {Link as AccessibleLink} from '@accessible/link'

const LinkButton = () => (
  <AccessibleLink>
    <button onClick={() => (window.location.href = '/foo')}>Go to /foo</button>
  </AccessibleLink>
)

API

Adds role="link" and tabIndex={0} props to its child component unless those props are already defined in the child component's props. Also adds a keydown event for the Enter key which causes the component's onClick property to fire.

Props
PropTypeDefaultRequired?Description
childrenReact.ReactElementundefinedYesThe component you want to add accessible roles and keydown events to.

useA11yLink(target, onClick)

A React hook for adding a11y properties and link/role=link interop to elements.

const Link = () => {
  const ref = React.useRef(null)
  const a11yProps = useA11yButton(ref, (event) => {
    // This is your `onClick` handler
    navigate.to('/home')
    event.preventDefault()
  })
  return <button {...a11yProps} ref={ref} />
}
Arguments
ArgumentTypeRequired?Description
targetReact.RefObject<T> | T | nullYesA React ref or HTML element
childrenReact.ReactElementYesThe component you want to turn into a button that handles focus and space, enter keydown events.
Returns
{
    readonly onClick: (event: React.MouseEvent<T, MouseEvent>) => void;
    readonly role: "button";
    readonly tabIndex: 0;
}

LICENSE

MIT

Keywords

FAQs

Last updated on 08 Jul 2020

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