lion/packages/select
github-actions[bot] f400425cf8 Version Packages
2021-01-06 16:44:27 +00:00
..
src fix: normalize dependencies 2021-01-06 10:53:38 +01:00
test feat(select): add types 2020-09-30 20:32:36 +02:00
CHANGELOG.md Version Packages 2021-01-06 16:44:27 +00:00
index.js feat: release inital public lion version 2019-04-26 10:37:57 +02:00
lion-select.js feat: release inital public lion version 2019-04-26 10:37:57 +02:00
package.json Version Packages 2021-01-06 16:44:27 +00:00
README.md fix: minimise deps by moving integration demos to integration packages 2021-01-06 16:34:03 +01:00

Select

lion-select component is a wrapper around the native select.

You cannot use interactive elements inside the options. Avoid very long names to facilitate the understandability and perceivability for screen reader users. Sets of options where each option name starts with the same word or phrase can also significantly degrade usability for keyboard and screen reader users.

import { html } from '@lion/core';

import './lion-select.js';

export default {
  title: 'Forms/Select',
};
export const main = () => html`
  <lion-select name="favoriteColor" label="Favorite color">
    <select slot="input">
      <option selected hidden value>Please select</option>
      <option value="red">Red</option>
      <option value="hotpink">Hotpink</option>
      <option value="teal">Teal</option>
    </select>
  </lion-select>
`;

For this form element it is important to put the slot="input" with the native select yourself, because you are responsible for filling it with <option>s. For most other form elements in lion we do this for you, because there's no need to put html inside the native form inputs.

Features

  • Catches and forwards the select events
  • Can be set to required or disabled

How to use

Installation

npm i --save @lion/select
import { LionSelect } from '@lion/select';
// or
import '@lion/select/lion-select.js';

Examples

Pre-select

You can preselect an option by setting the property modelValue.

export const preSelect = () => html`
  <lion-select name="favoriteColor" label="Favorite color" .modelValue=${'hotpink'}>
    <select slot="input">
      <option selected hidden value>Please select</option>
      <option value="red">Red</option>
      <option value="hotpink">Hotpink</option>
      <option value="teal">Teal</option>
    </select>
  </lion-select>
`;

Disabled

You can disable an option by adding the disabled attribute to an option.

export const disabledOption = () => html`
  <lion-select name="favoriteColor" label="Favorite color">
    <select slot="input">
      <option selected hidden value>Please select</option>
      <option value="red">Red</option>
      <option value="hotpink" disabled>Hotpink</option>
      <option value="teal">Teal</option>
    </select>
  </lion-select>
`;

Or by setting the disabled attribute on the entire lion-select field.

export const disabledSelect = () => html`
  <lion-select name="favoriteColor" label="Favorite color" disabled>
    <select slot="input">
      <option selected hidden value>Please select</option>
      <option value="red">Red</option>
      <option value="hotpink">Hotpink</option>
      <option value="teal">Teal</option>
    </select>
  </lion-select>
`;