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-alt

v0.0.5

Published

A web-accessible React select/menu/dropdown component. This project is a alternative from react-a11y-select, by mdesjardins.

Downloads

4

Readme

react-a11y-select-alt

A customizable select/dropdown react component with a focus on accessibility (a11y) and ease of use for developers. The goals of this project are:

  • Simplicity. The component should be as simple to use as its native HTML counterpart
  • Accessibility. The component should have accessibility compliance with full keyboard control.
  • Minimal styling.

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

Note 2: This project IS ASSOCIATED with the https://www.npmjs.com/package/react-a11y-select package/project. It is an extension with some improvements in the creation of select and option objects.

Live Demo

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

Installation

via npm

npm install react-a11y-select-alt

Usage

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

import { Select, Option } from 'react-a11y-select'
import 'react-a11y-select/src/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>

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.
  • cssClassName - If present, will concat with de default class of options.
  • customId - If present, will change the id option.

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