Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@anypoint-web-components/anypoint-listbox

anypoint-web-components2.7kApache-2.01.1.7TypeScript support: included

Anypoint styled list of options

web-components, anypoint-web-components, selection, listbox, list

readme

anypoint-listbox

Published on NPM

tests

The anypoint-listbox implements accessible list of options styled for the Anypoint platform.

<anypoint-listbox>
  <anypoint-item>Item 1</anypoint-item>
  <anypoint-item>Item 2</anypoint-item>
  <anypoint-item>Item 3</anypoint-item>
</anypoint-listbox>

Initial selection can be set by using selected property / attribute:

<anypoint-listbox selected="1">
  <anypoint-item>Item 1</anypoint-item>
  <anypoint-item>Item 2</anypoint-item>
  <anypoint-item>Item 3</anypoint-item>
</anypoint-listbox>

It allows multi selection by using multi property / attribute:

<anypoint-listbox multi>
  <anypoint-item>Item 1</anypoint-item>
  <anypoint-item>Item 2</anypoint-item>
  <anypoint-item>Item 3</anypoint-item>
</anypoint-listbox>

Children can be selected by any attribute instead of index:

<anypoint-listbox attrforselected="value" selected="2">
  <anypoint-item value="1">Item 1</anypoint-item>
  <anypoint-item value="2">Item 2</anypoint-item>
  <anypoint-item value="3">Item 3</anypoint-item>
</anypoint-listbox>

You can observe changes by listening to selected-changed event or by setting onselected property:

list.onselected = (e) => {
  console.log(e.target.selected);
};
// or
list.addEventListener('selected-changed', (e) => {
  console.log(e.target.selected);
  // also e.detail.value
});

Accessibility

<anypoint-listbox> has role="listbox" by default. A multi-select listbox will also have aria-multiselectable set. It implements key bindings to navigate through the listbox with the up and down arrow keys, esc to exit the listbox, and enter to activate a listbox item. Typing the first letter of a listbox item will also focus it.

The element also support aria-selected attribute set on children when useAriaSelected property is set. It should be used when the implementation uses different role where aria-selected is required.

<anypoint-listbox role="tablist" useAriaSelected>
  <button role="tab">Tab #1</button>
  <button role="tab">Tab #2</button>
  <button role="tab">Tab #3</button>
</anypoint-listbox>

Usage

Installation

npm install --save @anypoint-web-components/anypoint-listbox

In a LitElement template

import { LitElement, html } from 'lit-element';
import '@anypoint-web-components/anypoint-listbox/anypoint-listbox.js';
import '@anypoint-web-components/anypoint-item/anypoint-item.js';

class SimpleElement extends LitElement {
  render() {
    const { options, selected } = this;
    return html`
    <anypoint-listbox .selected="${selected}" @selected-changed="${this._selectedHandler}">
    ${options.map((item) => html`<anypoint-item>${item}</anypoint-item>`)}
    </anypoint-listbox>
    `;
  }

  _selectedHandler(e) {
    this.selected = e.target.value;
  }
}
window.customElements.define('simple-element', SimpleElement);

Development

git clone https://github.com/anypoint-web-components/anypoint-listbox
cd anypoint-listbox
npm install

Running the demo locally

npm start

Running the tests

npm test

changelog

1.1.0 (2020-05-17)

Build

Continuous integration

  • adding polymer.json for the CI pipeline c91aef9 by Pawel

Update

  • updating dependencies e1c329d by Pawel
  • upgrading dependencies 6e194f5 by Pawel

Documentation

  • updating demo page 11d6f9f by Pawel

Features

  • adding legacy state a5b8038 by Pawel
  • publishing stable version 4b91dcf by Pawel

Bug Fixes

  • updating demo page's title c8df1f7 by Pawel

Refactor

  • upgrading to open-wc standard 6b88978 by Pawel
  • move styles into render cb7f473 by TwoPlusTwoOne
  • deprecating legacy for compatibility 4d987c4 by Pawel

Testing

  • updating SL config fff8e53 by Pawel
  • updated Travis configuration to connect to Sauce Labs f6f2c84 by Pawel

Other

  • breaking: removing default value for useAriaSelected f6d40d0 by Pawel

1.1.1 (2020-05-29)

Build

Update

  • updating dev dependencies 2b069a5 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 3ccf57e by Ci agent

Documentation

  • updating readme file 732e854 by Pawel

Bug Fixes

  • fixing index.js import cf38a12 by Pawel

Refactor

  • upgrading to open-wc standard 6b88978 by Pawel

1.1.1 (2020-05-29)

Build

Update

  • [ci skip] automated merge master->stage. syncing main branches fbc6953 by Ci agent
  • updating dev dependencies 2b069a5 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 3ccf57e by Ci agent

Documentation

  • updating readme file 732e854 by Pawel

Bug Fixes

  • fixing index.js import cf38a12 by Pawel

1.1.2 (2020-06-24)

Build

Update

  • [ci skip] automated merge master->stage. syncing main branches 391b1f0 by Ci agent
  • [ci skip] automated merge master->stage. syncing main branches fbc6953 by Ci agent
  • updating dev dependencies 2b069a5 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 3ccf57e by Ci agent

Documentation

  • updating readme file 732e854 by Pawel

Bug Fixes

  • fixing types declaration cf26f4c by Pawel
  • fixing index.js import cf38a12 by Pawel

1.1.3 (2020-06-24)

Update

  • [ci skip] automated merge master->stage. syncing main branches 0dc949b by Ci agent
  • [ci skip] automated merge master->stage. syncing main branches 391b1f0 by Ci agent
  • [ci skip] automated merge master->stage. syncing main branches fbc6953 by Ci agent

Bug Fixes

  • renaming interfaces in types declaration fdd9994 by Pawel
  • fixing types declaration cf26f4c by Pawel

1.1.4 (2020-06-24)

Build

Update

  • updating the mixins a1d465d by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 110dc7c by Ci agent
  • [ci skip] automated merge master->stage. syncing main branches 0dc949b by Ci agent

Bug Fixes

  • renaming interfaces in types declaration fdd9994 by Pawel

1.1.5 (2020-10-26)

Build

Update

  • [ci skip] automated merge master->stage. syncing main branches 17d544d by Ci agent
  • updating the mixins a1d465d by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 110dc7c by Ci agent

Bug Fixes

1.1.6 (2020-11-25)

Build

  • bumping version ee63ba7 by Pawel Psztyc

Continuous integration

  • adding GH action cf222d9 by Pawel Psztyc

Update

  • updating types 1373f5a by Pawel Psztyc
  • reformatting HTML aecb1d2 by Pawel Psztyc
  • [ci skip] automated merge master->stage. syncing main branches 57a670a by Ci agent
  • [ci skip] automated merge master->stage. syncing main branches 17d544d by Ci agent

Bug Fixes

Testing

  • updating tests runner 967dba8 by Pawel Psztyc