An open API service indexing awesome lists of open source software.

https://github.com/19h47/19h47-listbox

📝
https://github.com/19h47/19h47-listbox

listbox option

Last synced: 6 months ago
JSON representation

📝

Awesome Lists containing this project

README

        

# @19h47/listbox

Collapsible single-select listbox widget

## Installation

```
yarn add @19h47/listbox
```

## Usage

```javascript
const $list = document.querySelector('.js-list');

const $listbox = $list.querySelector('[role="listbox"]');
const $button = $list.querySelector('.js-list-button');

// Init box.
const box = new Listbox.Box($listbox);
box.init();

// Init button.
const button = new Listbox.Button($button, box);
button.init();
```

```html


Choose an monster


Bat


```

## Keyboard Support

The example listbox on this page implements the following keyboard interface.

| Key | Function |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Enter | - If the focus is on the button, expands the listbox and places focus on the currently selected option in the list.
- If focus is in the listbox , collapses the listbox and keeps the currently selected option as the button label. |
| Escape | If the listbox is displayed, collapses the listbox and moves focus to the button. |
| Down Arrow | - Moves focus to and selects the next option.
- If the listbox is collapsed, also expands the list. |
| Up Arrow | - Moves focus to and selects the previous option.
- If the listbox is collapsed, also expands the list. |
| Home | If the listbox is displayed, moves focus to and selects the first option. |
| Printable Characters | - Type a character: focus moves to the next item with a name that starts with the typed character.
- Type multiple characters in rapid succession: focus moves to the next item with a name that starts with the string of characters typed. |

## Event

```
Button.change
```

## Options

```
delay
```

## Example

An example is located right [here](https://19h47.github.io/19h47-list/), see [sources](/docs/index.html).

## References

- [Example of Tabs with Manual Activation](https://www.w3.org/TR/wai-aria-practices-1.1/examples/listbox/listbox-collapsible.html)
- [Keycode](https://keycode.info/) by [Wes Bos](https://wesbos.com/)