Combobo

Combination Box built with accessibility in mind.

Installation

$ npm install combobo

Usage

In the browser

Just include combobo.js.

<body>
  <script src="./node_modules/combobo/dist/combobo.js"></script>
  <script>
    var combobo = new Combobo();
  </script>
</body>

With browserify

const Combobo = require('combobo');
const combobo = new Combobo();

Options

Example Combobo call with options

var combobo = new Combobo({
  input: '.combobox',
  list: '.listbox',
  options: '.option', // qualified within `list`
  groups: null, // qualified within `list`
  openClass: 'open',
  activeClass: 'active',
  selectedClass: 'selected',
  useLiveRegion: true,
  multiselect: false,
  noResultsText: null,
  selectionValue: (selecteds) => selecteds.map((s) => s.innerText.trim()).join(' - '),
  optionValue: 'underline', // wrap the matched portion of the option (if applicable) in a span with class "underline"
  announcement: {
    count: (n) => `${n} options available`,
    selected: 'Selected.'
  },
  filter: 'contains' // 'starts-with', 'equals', or funk
});

Events

Add an event listener with .on, remove event listener with .off (see example below)

var combobo = new Combobo();

combobo
  .on('change', function () {
    console.log('stuff has changed and stuff');
  })
  .on('selection', function () {
    console.log('selection made!');
  });

Methods

Example usage

// move 5 options forward and select the option
combobo
  .goTo(combobo.getOptIndex() + 5)
  .select();

Running tests

$ npm run test

Running only selected tests

Utilize it.only or even describe.only in unison with npm run test:dev