Attach combobox navigation behavior to or .</body></html>
Перейти к файлу
Mu-An ✌️ Chiou 6128691ef5
Set env to osx to test ctrl np shortcut
2018-11-08 08:21:49 -05:00
examples Initial commit 2018-11-06 15:37:49 -05:00
test Add test for APIs 2018-11-07 11:29:49 -05:00
.eslintrc.json Initial commit 2018-11-06 15:37:49 -05:00
.flowconfig Initial commit 2018-11-06 15:37:49 -05:00
.gitignore Initial commit 2018-11-06 15:37:49 -05:00
.travis.yml Set env to osx to test ctrl np shortcut 2018-11-08 08:21:49 -05:00
LICENSE Initial commit 2018-10-11 13:10:36 -07:00
README.md Navigates to +- 1 2018-11-07 11:29:35 -05:00
combobox-nav.js Initial commit 2018-11-06 15:37:49 -05:00
combobox-nav.js.flow Initial commit 2018-11-06 15:37:49 -05:00
package-lock.json Initial commit 2018-11-06 15:37:49 -05:00
package.json Initial commit 2018-11-06 15:37:49 -05:00
prettier.config.js Initial commit 2018-11-06 15:37:49 -05:00
rollup.config.js Initial commit 2018-11-06 15:37:49 -05:00

README.md

Combobox Navigation

Attach combobox navigation behavior to <input> or <textarea>.

Installation

$ npm install @github/combobox-nav

Usage

HTML

<label>
  Robot
  <input id="robot-input" aria-owns="list-id" role="combobox" type="text">
</label>
<ul role="listbox" id="list-id">
  <li id="baymax" role="option">Baymax</li>
  <li><del>BB-8</del></li><!-- `role=option` needs to be present for item to be selectable -->
  <li id="hubot" role="option">Hubot</li>
  <li id="r2-d2" role="option">R2-D2</li>
</ul>

JS

import {install, navigate, uninstall} from '@github/combobox-nav'
const input = document.querySelector('#robot-input')
const list = document.querySelector('#list-id')

// To install this behavior
install(input, list)
// To move selection to the nth+1 item in the list
navigate(input, list, 1)
// To uninstall this behavior
uninstall(input, list)

Events

A bubbling combobox-commit event is fired on the list element when an option is selected via keyboard or click.

For example, autocomplete when an option is selected:

list.addEventListener('combobox-commit', function(event) {
  console.log('Element selected: ', event.target)
})

Development

npm install
npm test