npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-a11y-select

v1.0.4

Published

A web-accessible React select/menu/dropdown component

Downloads

719

Readme

react-a11y-select

Travis npm package

A customizable select/dropdown react component with a focus on accessibility (a11y) and ease of use for developers. The goal of this project is to make the component as simple to use as its native HTML counterpart, with improved flexibility of HTML formatted options, and accessibility compliance with full keyboard control.

Note: this project isn't associated with the https://github.com/reactjs/react-a11y package/project - it's an unfortunate naming collision. (v_v)

Live Demo

http://mikedesjardins.net/react-a11y-select/

Installation

via npm

npm install react-a11y-select

Usage

Here is a very simple example for how to use the component:

import { Select, Option } from 'react-a11y-select'
import 'react-a11y-select/styles.css'
...

<Select>
  <Option value="apple">
    <img src="apple.png" role="presentation" />
    Apple
  </Option>
  <Option value="cherry">
     <img src="cherry.png" role="presentation" />
     Cherry
  </Option>
</Select>

Simple, right? This will render an unordered list styled as a dropdown/select box. Importantly, it will have all of the correct ARIA and role attributes to make it usable by screen readers, and it will respond as expected to keyboard input.

Props

The following properties are on the <Select> component:

  • label - the ARIA label attribute for the component. Briefly describes the form field for screen readers. Either label or labelledBy are required.
  • labelledBy - the ARIA labelledBy attribute for the compoent. Set to the ID of a <label> DOM element which briefly describes the form field to screen readers (note: this is likely going to be deprecated soon)
  • placeholderText - what appears in the dropdown before a value is selected. Defaults to "Please choose..."
  • indicator - Unicode character that is used for the arrow indicator in the component. Defaults to &#x25be which is rendered as ▾
  • initialValue - The initial value for the dropdown.
  • onChange - a handler that is called when the select box value changes. Passed the value that was selected.
  • buttonId - a value for the id attribute associated with the button. Useful if you have a <label> element and want to set its for attribute to this component. If not provided, one is autogenerated.
  • listId - a value for the id attribute of the element that represents the list of options. If not provided, one is autogenerated.

The following properties are available on the <Option> component:

  • value - The value associated with the Option.
  • label - An ARIA label that assisted technologies can use in place to interpret the content of the option. Defaults to the value.
  • disabled - If present, sets a disabled class and ignores onClick and onMouseOver events.

This is very much a work-in-progress

There's still a lot more to do on this project and most of it is in flux. It needs more tests, more features, more everything. Even when it's finished, it will probably be most valuable as a "demonstration" component to serve as inspiration for your own work. The props and API are subject to change. Here's a list of my TODOs:

  • More tests. I'd love to take the ARIA best practices document (https://www.w3.org/TR/wai-aria-practices/#menubutton) and turn it into unit tests.
  • Use Flow (or Typescript?) for typechecking.
  • An <OptGroup> element would be nice, along with Separators.
  • Need to record a screencast of the screen reader in action.
  • Need to look at selecting a letter jumping in the list.
  • Add other callbacks?

See this project's Github issues for other stuff.

Was this project not quite what you were looking for?

Check out David Clark's awesome aria menubutton project: https://github.com/davidtheclark/react-aria-menubutton It's another implementation of a React dropdown component where web accessibility is a primary goal.

Also take a look at Kent C. Dodd's Downshift project in Paypal's repo: https://github.com/paypal/downshift It's a far more robust and customizable set of tools for building your own accessible select components, and uses the somewhat less common (but far more flexible) solution of requiring developers to implement their own render methods.

I haven't personally used either of the above libraries in a project (yet), but they both look fantastic and might be just what you need!

License

MIT