Giter Club home page Giter Club logo

listbox's Introduction

Listbox โ™ฟ๐Ÿ“๐Ÿ“ฆ

Build & compose WAI-ARIA compliant listbox based UI widgets.

Usage

Install it with yarn add listbox or npm install listbox and try out this piece of JSX:

import { Listbox, Option, OptionsList } from "listbox"

<Listbox>
  <OptionsList>
    <Option>Ford Motor Co.</Option>
    <Option>Mazda Motor Corp.</Option>
    <Option>Tesla Inc.</Option>
  </OptionsList>
</Listbox>

This is a primitive listbox component. It abstracts away core listbox behavior and accessibility. It has no opinion on layout or styling and can be composed into other listbox based UI widgets with little code. See what kinds of widgets can composed using a primitive listbox under "Live Playground".

Live Playground

Check out the live, editable code examples on CodeSandbox here:

Listbox (base): CodeSandBox | Storybook

Listbox (grid): CodeSandBox | Storybook

Scrollable Listbox: CodeSandBox | Storybook

Collapsible Dropdown: CodeSandBox | Storybook

Collapsible Dropdown (Grid): CodeSandBox | Storybook

ComboBox: CodeSandBox | Storybook

GitHub Icon GitHub Reaction Popup: CodeSandBox | Storybook

Shipt Icon Shipt Search Autocomplete: CodeSandBox | Storybook

Slack Icon Slack Mention Autocomplete: CodeSandBox | Storybook

Local Development

Storybook is used to interactively develop the UI components with hot reloading. This Storybook is published here.

To run Storybook:

Clone this repository

git clone [email protected]:hzhu/listbox.git

Install dependencies

yarn install

Run Storybook

yarn run storybook

Navigate to http://localhost:9009 to see live code changes during local development.

Testing

This project uses Jest and react-testing-library ๐Ÿ for testing.

To run the tests

yarn test

or to continuously watch

yarn test --watch

listbox's People

Contributors

hzhu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

listbox's Issues

Screenreader does not say aloud complete listbox and option information

Symptom

For a listbox with three options, the screen reader does not say aloud โ€œOption 3 (3 of 10)โ€. Rather it just says โ€œOption 3".

Problem

It appears that the accessibility tree is build in a way that the parent element of the options or listitems is presumed to be a listbox or list of items, respectively. Screen readers and assistive technologies might not work as intended if a parent element contains non-semantic children elements. This is probably why <div>s shouldn't be used as children inside a <ul>:

// don't do this
<ul>
  <div>One</div>
  <div>Two</div>
</ul>

This is bad and the screen reader wonโ€™t say โ€œOption 3 (3 of 10)โ€ and it will just say โ€œOption 3":

<div role="listbox">
  <ul>
    <li role="option">Option 1</li>
  </ul>
</div>

Solution

We can write composite widgets similar to native widgets by giving them proper semantics using ARIA roles. Below are three good ways to author a composite listbox component:

  1. This is good and should be the preferred way to write build a listbox widget:
<ul role="listbox">
  <li role="option">Option 1</li>
</ul>
  1. And this is good too:
<div role="listbox">
  <div role="option">Option 1</div>
</div>
  1. This seems to be good too:
<div role="listbox">
  <ul role="presentation">
    <li role="option">Option 1</li>
  </ul>
</div>

The role="presentation" remove semantic meaning from the <ul>. The <li> (options) don't "belong" to the <ul> anymore, rather they belong to the <div> with role="listbox".

  1. And finally this is good too:
<div role="listbox">
  <div role="presentation">
    <div role="option">Option 1</div>
  </div>
</div>

For this project I'm going to try out the last alternative because I would like the listbox to possibly support grid based listboxes like an emoji picker.

<div role="listbox">
  <div role="presentation">
    <div role="option">โšพ๏ธ</div>
    <div role="option">๐Ÿ€</div>
    <div role="option">โšฝ๏ธ</div>
  </div>
  <div role="presentation">
    <div role="option">๐Ÿˆ</div>
    <div role="option">๐Ÿ‰</div>
    <div role="option">๐Ÿ</div>
  </div>
</div>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.