1.1.7 • Published 3 years ago

@anypoint-web-components/anypoint-listbox v1.1.7

Weekly downloads
632
License
Apache-2.0
Repository
github
Last release
3 years ago

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
@infinitebrahmanuniverse/nolb-_any@everything-registry/sub-chunk-71@anypoint-web-components/anypoint-autocomplete@api-components/api-headers-form@api-components/api-method-documentation@api-components/api-property-form-item@api-components/api-forms@api-client/har@api-components/api-server-selector@api-components/api-authorization@api-components/api-body-editor@api-components/api-url-params-editor@advanced-rest-client/cookies-list-items@advanced-rest-client/environment-selector@advanced-rest-client/export-options@advanced-rest-client/export-panel@advanced-rest-client/variables-editor@advanced-rest-client/rest-apis-list-panel@advanced-rest-client/saved-requests-panel@advanced-rest-client/themes-panel@advanced-rest-client/request-actions-panel@advanced-rest-client/request-editor@advanced-rest-client/project-details@advanced-rest-client/api-authorization@advanced-rest-client/arc-actions@advanced-rest-client/arc-app-mixin@advanced-rest-client/about-arc-electron@advanced-rest-client/arc-menu@advanced-rest-client/arc-models@advanced-rest-client/arc-project@advanced-rest-client/arc-request-ui@advanced-rest-client/arc-response@advanced-rest-client/arc-settings@advanced-rest-client/arc-settings-panel@advanced-rest-client/arc-url@advanced-rest-client/arc-websocket@advanced-rest-client/auth-methods@advanced-rest-client/authorization@advanced-rest-client/authorization-method@advanced-rest-client/authorization-panel@advanced-rest-client/authorization-selector@advanced-rest-client/history-panel@advanced-rest-client/host-rules-editor@advanced-rest-client/http-method-selector@advanced-rest-client/json-table@advanced-rest-client/arc-environment@advanced-rest-client/body-editor@advanced-rest-client/client-certificates@advanced-rest-client/client-certificates-panel@advanced-rest-client/code-mirror@advanced-rest-client/code-mirror-hint@advanced-rest-client/arc-ie@advanced-rest-client/content-type-selector@advanced-rest-client/cookie-manager@zalastax/nolb-_any
1.1.7

3 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago