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

Package detail

@anypoint-web-components/anypoint-selector

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

Port of iron-selector that works with ES6 classes. Manages a list of elements that can be selected.

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

readme

Published on NPM

Build Status

Published on webcomponents.org

anypoint-selector

This is a port of iron-selector that works with LitElement and ES6 classes, originally developed by Polymer team.

<anypoint-selector>, AnypointSelectableMixin, AnypointMultiSelectableMixin

anypoint-selector is an element which can be used to manage a list of elements that can be selected. Tapping on the item will make the item selected. The selected indicates which item is being selected. The default is to use the index of the item. anypoint-selector's functionality is entirely defined by AnypointMultiSelectableMixin.

AnypointSelectableMixin gives an element the concept of a selected child element. By default, the element will select one of its selectable children when a click event is dispatched to it.

AnypointSelectableMixin lets you ...

  • decide which children should be considered selectable (selectable),
  • retrieve the currently selected element (selectedItem) and all elements in the selectable set (items),
  • change the selection (select, selectNext, etc.),
  • decide how selected elements are modified to indicate their selected state (selectedClass, selectedAttribute),

... among other things.

AnypointMultiSelectableMixin includes all the features of AnypointSelectableMixin as well as a multi property, which can be set to true to indicate that the element can have multiple selected child elements. It also includes the selectedItems and selectedValues properties for working with arrays of selectable elements and their corresponding values (multi is true) - similar to the single-item versions provided by AnypointSelectableMixin: selectedItem and selected.

The element has no own shadow DOM. Items are rendered as is. The element also covers a case where the selector is used in another custom element and a <slot> is passed as a child (e.g. dropdown list wit children defined in light DOM).

Usage

Installation

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

In an html file

<html>
  <head>
    <script type="module">
      import '@anypoint-web-components/anypoint-selector/anypoint-selector.js';
    </script>
  </head>
  <body>
    <anypoint-selector selected="0">
      <div>Item 0</div>
      <div>Item 1</div>
      <div>Item 2</div>
      <div>Item 3</div>
      <div>Item 4</div>
    </anypoint-selector>
    <script>
    {
      document.querySelector('files-payload-editor').onselect = (e) => {
        console.log(e.detail.value);
      };
    }
    </script>
  </body>
</html>

In a LitElement template

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

class SampleElement extends LitElement {
  render() {
    return html`
    <anypoint-selector @select="${this._selectedHandler}"></anypoint-selector>
    `;
  }

  _selectedHandler(e) {
    console.log('current selection:', e.detail.item);
  }
}
customElements.define('sample-element', SampleElement);

Development

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

Running the demo locally

npm start

Running the tests

npm test

changelog

1.1.0 (2020-05-17)

Build

  • bumping version 602808f by Pawel
  • bumping version c755fcf by Pawel
  • bumping version 5814509 by Pawel
  • publishing stable release 6e54fab by Pawel

Update

  • upgrading to open-wc standards b1e34ca by Pawel
  • updating eslint config 16612ea by Pawel
  • updating dependencies 924454e by Pawel
  • adding license and contrib files 1fbb3f0 by Pawel

Features

  • selection / activation events now bubbling 194b9c4 by Pawel

Bug Fixes

  • fixing value change to add 0 to the test ecd9111 by Pawel
  • fixing linter error 94f2820 by Pawel
  • fixing audit errors e898e13 by Pawel

Testing

  • updated Travis configuration to connect to Sauce Labs 1517688 by Pawel

1.1.1 (2020-05-17)

Build

Update

  • adding index export to types 5ed747a by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 7c22302 by Ci agent
  • upgrading to open-wc standards b1e34ca by Pawel

1.1.2 (2020-05-17)

Build

Update

  • fixing types for multi selector mixin 0bb1244 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches cc2ed03 by Ci agent
  • adding index export to types 5ed747a by Pawel

1.1.3 (2020-06-19)

Build

Update

  • restoring previous version of eslint 1b5428f by Pawel
  • removing js from d.ts file 6689b0f by Paweł Psztyć
  • [ci skip] automated merge master->stage. syncing main branches 41e8110 by Ci agent
  • fixing types for multi selector mixin 0bb1244 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches cc2ed03 by Ci agent

Features

  • adding new events API 68d5591 by Pawel

1.1.4 (2020-06-24)

Build

Update

  • [ci skip] automated merge master->stage. syncing main branches b2d2f2b by Ci agent
  • restoring previous version of eslint 1b5428f by Pawel
  • removing js from d.ts file 6689b0f by Paweł Psztyć
  • [ci skip] automated merge master->stage. syncing main branches 41e8110 by Ci agent

Features

  • adding new events API 68d5591 by Pawel

Bug Fixes

  • fixing type export 6db2376 by Pawel

1.1.5 (2020-09-27)

Update

  • adding better ts support cd88f55 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 3581dd4 by Ci agent
  • [ci skip] automated merge master->stage. syncing main branches b2d2f2b by Ci agent

Bug Fixes

  • fixing type export 6db2376 by Pawel

1.1.6 (2020-11-21)

Update

  • upgarding test framework 0918995 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 047ac01 by Ci agent
  • adding better ts support cd88f55 by Pawel
  • [ci skip] automated merge master->stage. syncing main branches 3581dd4 by Ci agent

Features

  • adding the selected event 4e5a5ff by Pawel