Skip to content

Select <l-select> ​

Build a select two ways. For a simple single select, style a native <select> with class="l-select" — zero-JS and the recommended default. For in-popover search, multi-select with chips, or async options, reach for the <l-select> custom element.

HTML tag<select>
⏣Native
⬡Progressive
◇Plain
⬢Shadow-DOM
Native element
html
<select class="l-select">
  <option>France</option>
  <option>Germany</option>
</select>

Basic ​

Add class="l-select" to a native <select> — its <option>s are styled automatically. Built on the Customizable Select API (appearance: base-select), degrading to a native <select> where unsupported — so always keep meaningful text in each <option>.

Code
html
<select
  class="l-select"
  aria-label="Plan"
>
  <option value="free">Free</option>
  <option value="pro">Pro</option>
  <option value="team">Team</option>
</select>

Disabled ​

Native disabled attribute, on the <select> for the whole control or on an individual <option>. To disable a group of fields at once, wrap them in <fieldset disabled> — see Form field.

html
<select
  class="l-select"
  disabled
>
  <option>France</option>
  <option disabled>Germany</option>
</select>

Rich options ​

Put markup inside each <option> — wrap a .l-select-item-title over a .l-select-item-description in .l-select-item-text (add a .l-select-item-media image or icon before it). A <button><selectedcontent></button> trigger mirrors the chosen option.

Code
html
<select
  class="l-select"
  aria-label="Merge method"
>
  <button>
    <selectedcontent></selectedcontent>
  </button>

  <option
    value="squash"
    selected
  >
    <span class="l-select-item-text">
      <span class="l-select-item-title">Squash and merge</span>
      <span class="l-select-item-description">
        The 1 commit from this branch will be added to the base branch.
      </span>
    </span>
  </option>

  <option value="rebase">
    <span class="l-select-item-text">
      <span class="l-select-item-title">Rebase and merge</span>
      <span class="l-select-item-description">
        The 1 commit from this branch will be rebased and added to the base branch.
      </span>
    </span>
  </option>
</select>

Suffix ​

Add a .l-select-item-suffix after .l-select-item-text to pin a badge, a count or a status icon to the end of the row. It sits on the title's line and keeps its natural width while the text column gives way, so a long title truncates with an ellipsis. Like the description, the suffix stays in the picker: <selectedcontent> mirrors only the media and the title into the trigger. Screen readers announce the suffix with its option, so write it as words ("12 members", not "12").

Don't add a label attribute to native options: a labelled option paints its label instead of its rich children.

Code
html
<select
  class="l-select"
  aria-label="Team"
>
  <button>
    <selectedcontent></selectedcontent>
  </button>

  <option
    value="design"
    selected
  >
    <span class="l-select-item-text">
      <span class="l-select-item-title">Design</span>
      <span class="l-select-item-description">Product and brand design</span>
    </span>
    <span class="l-select-item-suffix">
      <l-badge
        size="sm"
        appearance="filled"
        >12 members</l-badge
      >
    </span>
  </option>

  <option value="engineering">
    <span class="l-select-item-text">
      <span class="l-select-item-title">Engineering</span>
      <span class="l-select-item-description">Platform, web and mobile apps</span>
    </span>
    <span class="l-select-item-suffix">
      <l-badge
        size="sm"
        appearance="filled"
        >48 members</l-badge
      >
    </span>
  </option>

  <option value="support">
    <span class="l-select-item-text">
      <span class="l-select-item-title">Support</span>
      <span class="l-select-item-description">Customer success and onboarding</span>
    </span>
    <span class="l-select-item-suffix">
      <l-badge
        size="sm"
        appearance="filled"
        variant="warning"
        >Full</l-badge
      >
    </span>
  </option>
</select>

Enhanced: <l-select> ​

When the native tier isn't enough, the <l-select> custom element adds in-popover search, multi-select with removable chips, and async options. It needs its JS module (import 'luxen-ui/select'). Options are authored as a native <datalist> of <option> — the same surface as <l-combobox> — with <option selected> for pre-selection.

HTML tag<l-select>
⏣Native
⬡Progressive
◇Plain
⬢Shadow-DOM
Shadow-DOM Custom Element

Searchable ​

Add searchable for a filter box inside the popover — useful for long lists. Matching is accent/case-insensitive.

Code
html
<div class="w-72">
  <l-select
    searchable
    label="Country"
    name="country"
    placeholder="Select a country…"
  >
    <datalist>
      <option value="us">United States</option>
      <option value="fr">France</option>
      <option value="de">Germany</option>
      <option value="es">Spain</option>
      <option value="it">Italy</option>
      <option value="jp">Japan</option>
      <option value="br">Brazil</option>
    </datalist>
  </l-select>
</div>

Multiple ​

Add multiple to select several values. The trigger shows a removable <l-tag> chip per value and the form submits one entry per value under name.

Code
html
<div class="w-72">
  <l-select
    multiple
    label="Tags"
    name="tags"
    placeholder="Select tags…"
  >
    <datalist>
      <option
        value="design"
        selected
      >
        Design
      </option>
      <option value="dev">Development</option>
      <option value="qa">QA</option>
      <option value="ops">Ops</option>
    </datalist>
  </l-select>
</div>

Rich options ​

The same .l-select-item-* classes as the native tier work inside each <option>. Set a label (or .l-select-item-title) so filtering and the trigger display use the title.

With searchable, the query is highlighted inside .l-select-item-title and .l-select-item-description, the same way as plain options. Only the text is wrapped in <mark>; the option's markup is kept as authored.

Code
html
<div class="w-72">
  <l-select
    searchable
    label="Country"
    placeholder="Select a country…"
  >
    <datalist>
      <option
        value="us"
        label="United States"
      >
        <span class="l-select-item-media"><l-icon name="circle-flags:us"></l-icon></span>
        <span class="l-select-item-text">
          <span class="l-select-item-title">United States</span>
          <span class="l-select-item-description">North America</span>
        </span>
      </option>
      <option
        value="fr"
        label="France"
      >
        <span class="l-select-item-media"><l-icon name="circle-flags:fr"></l-icon></span>
        <span class="l-select-item-text">
          <span class="l-select-item-title">France</span>
          <span class="l-select-item-description">Europe</span>
        </span>
      </option>
      <option
        value="jp"
        label="Japan"
      >
        <span class="l-select-item-media"><l-icon name="circle-flags:jp"></l-icon></span>
        <span class="l-select-item-text">
          <span class="l-select-item-title">Japan</span>
          <span class="l-select-item-description">Asia</span>
        </span>
      </option>
    </datalist>
  </l-select>
</div>

The .l-select-item-suffix works the same way, and stays out of the trigger, the chips and the search. Rich options are copied into the popover's shadow root: an <l-badge> is styled there, but your page's own selectors don't reach that copy. To theme it, set the badge's CSS custom properties on the <l-select>: they inherit into the popover.

Code
html
<div class="w-80">
  <l-select
    label="Team"
    placeholder="Select a team…"
  >
    <datalist>
      <option
        value="design"
        label="Design"
      >
        <span class="l-select-item-text">
          <span class="l-select-item-title">Design</span>
          <span class="l-select-item-description">Product and brand design</span>
        </span>
        <span class="l-select-item-suffix">
          <l-badge
            size="sm"
            appearance="filled"
            >12 members</l-badge
          >
        </span>
      </option>
      <option
        value="engineering"
        label="Engineering"
      >
        <span class="l-select-item-text">
          <span class="l-select-item-title">Engineering</span>
          <span class="l-select-item-description">Platform, web and mobile apps</span>
        </span>
        <span class="l-select-item-suffix">
          <l-badge
            size="sm"
            appearance="filled"
            >48 members</l-badge
          >
        </span>
      </option>
      <option
        value="support"
        label="Support"
      >
        <span class="l-select-item-text">
          <span class="l-select-item-title">Support</span>
          <span class="l-select-item-description">Customer success and onboarding</span>
        </span>
        <span class="l-select-item-suffix">
          <l-badge
            size="sm"
            appearance="filled"
            variant="warning"
            >Full</l-badge
          >
        </span>
      </option>
    </datalist>
  </l-select>
</div>

Clearable ​

Add with-clear for a button that resets the value.

Taller controls ​

The clear button and the chevron each take a square as tall as the field, borders excluded: their hit area and the space between them grow with the control. Set --height on the element, or --l-form-control-height on an ancestor to resize every form control at once. The glyphs keep their size; resize them with --l-form-control-icon-size (default 1em).

Code
html
<div class="w-72">
  <l-select
    label="Country"
    with-clear
    class="[--height:42px]"
  >
    <datalist>
      <option value="us">United States</option>
      <option
        value="fr"
        selected
      >
        France
      </option>
      <option value="de">Germany</option>
      <option value="es">Spain</option>
    </datalist>
  </l-select>
</div>

Custom filter ​

Options are matched case- and accent-insensitively (every space-separated keyword must appear). Override the filter property — (item, query) => boolean — for startsWith, fuzzy, or remote-driven filtering.

The default filter only reads the label (a rich option's title). To search the description too, match against the text of item.html — the match is then highlighted in the description as well. Try a capital or a continent:

Code
html
<div class="w-72">
  <l-select
    id="demo-select-filter"
    searchable
    label="Country"
    placeholder="Select a country…"
  >
    <datalist>
      <option
        value="fr"
        label="France"
      >
        <span class="l-select-item-text">
          <span class="l-select-item-title">France</span>
          <span class="l-select-item-description">Capital: Paris · Europe</span>
        </span>
      </option>
      <option
        value="jp"
        label="Japan"
      >
        <span class="l-select-item-text">
          <span class="l-select-item-title">Japan</span>
          <span class="l-select-item-description">Capital: Tokyo · Asia</span>
        </span>
      </option>
      <option
        value="br"
        label="Brazil"
      >
        <span class="l-select-item-text">
          <span class="l-select-item-title">Brazil</span>
          <span class="l-select-item-description">Capital: Brasília · South America</span>
        </span>
      </option>
      <option
        value="ke"
        label="Kenya"
      >
        <span class="l-select-item-text">
          <span class="l-select-item-title">Kenya</span>
          <span class="l-select-item-description">Capital: Nairobi · Africa</span>
        </span>
      </option>
    </datalist>
  </l-select>
</div>
js
const select = document.querySelector('l-select');

// `item.html` is the rich option's markup: compare against its text, not its tags.
const textOf = (html) => {
  const template = document.createElement('template');
  template.innerHTML = html;
  return template.content.textContent;
};

select.filter = (item, query) =>
  `${item.label} ${item.html ? textOf(item.html) : ''}`
    .toLowerCase()
    .includes(query.trim().toLowerCase());

Match highlight ​

With searchable, the part of each option that matches the query is wrapped in <mark>. Theme it with two form-control tokens.

css
:root {
  --l-form-control-match-background-color: transparent;
  --l-form-control-match-font-weight: var(--l-font-weight-bold);
}

Dynamic options ​

The <datalist> is watched: re-labelling, adding, removing, or disabling an <option> after mount updates the trigger and the listbox immediately — no reopen, no remount. Framework re-renders patch the existing <option> nodes in place, so a localized picker re-labels itself when the interface language changes.

js
const option = document.querySelector('l-select option[value="fr"]');

// The closed trigger re-renders on its own — nothing to call, nothing to remount.
option.label = 'Français';

Accessibility ​

The native tier inherits the platform's <select> semantics — pair it with a <label>. The criteria below cover the <l-select> custom element.

Criteria ​

Role

The trigger is a role="combobox" named by label, so the chosen value is announced alongside it, and exposes aria-haspopup="listbox" / aria-expanded / aria-controls; options are role="option" in a role="listbox" (with aria-multiselectable when multiple)

WCAG4.1.2
RGAA11.1
Accessible name

Set label (or wrap with <l-form-field>)

WCAG1.3.1
RGAA11.1
Focus management

Opening moves focus into the search box (or the listbox when not searchable); closing returns it to the trigger

WCAG2.4.3
RGAA12.8
Target size

The trigger and chip remove buttons keep a minimum 24×24px hit target

WCAG2.5.8
RGAA13.10

Rules

  • Always set label so the trigger has an accessible name

Keyboard interactions ​

Enter / Space / ArrowDown
Opens the listbox (focus moves to the search box when searchable, else the list)
ArrowDown / ArrowUp
Moves the active option
Enter
Selects the active option (single) or toggles it (multiple)
Escape
Closes the listbox and returns focus to the trigger
Backspace / Delete
Removes a focused chip (multiple)

API reference ​

The native tier ships its styles via luxen-ui/css/select; the reference below is for the <l-select> custom element.

Importing ​

js
import 'luxen-ui/select';
css
@import 'luxen-ui/css/select';

Attributes & Properties ​

placeholderstringProperty
Placeholder shown in the trigger when nothing is selected.
labelstringProperty
Accessible label for the trigger.
sizeSelectSizedefault:'md'Property
Control size.
searchablebooleandefault:falseProperty
Show a filter box inside the popover (opt-in, for long lists).
with-clearbooleandefault:falseProperty
Show a button to clear the value.
placementPlacementdefault:'bottom-start'Property
Panel placement relative to the trigger.
multiplebooleandefault:falseProperty
Allow selecting multiple values — renders chips and submits one entry per value.
filterSelectFilterdefault:defaultFilterProperty
Override the option filter. (item, query) => boolean.
valuestring | string[]Property
The selected value (single mode) or array of values (multiple mode).
validationTargetProperty

Events ​

changeEvent
Fired when the selection changes. Bubbles. Not cancelable. Properties: value: string | string[].
inputEvent
Fired as the user types in the search box. Bubbles. Not cancelable. Properties: value: string (the query).
showcancelableEvent
Fired before the listbox opens. Cancelable.
hidecancelableEvent
Fired before the listbox closes. Cancelable.

CSS parts ​

basePart
The host wrapper.
triggerPart
The button that opens the listbox.
valuePart
The selection display inside the trigger.
chevronPart
The trigger chevron.
clearPart
The clear button.
panelPart
The floating popover panel.
searchPart
The search input.
listboxPart
The options container.
optionPart
Each option row.
emptyPart
The "no results" message.

CSS classes ​

.l-select-item-mediaClass
Rich option: leading image or icon.
.l-select-item-textClass
Rich option: column holding the title and the description.
.l-select-item-titleClass
Rich option: title, truncated with an ellipsis. Used as the label when the option has no label.
.l-select-item-descriptionClass
Rich option: secondary line, shown in the listbox only.
.l-select-item-suffixClass
Rich option: trailing badge, count or status icon on the title's line. Kept out of the trigger, the chips and the search.

CSS custom properties ​

--heightdefault:var(--l-form-control-height)Custom property
Control height. The clear button and the chevron each take a square of this height (borders excluded), so their hit area and spacing follow it.
--l-form-control-icon-sizedefault:1emCustom property
Glyph size of the clear button and the chevron (global form-control token; set it here or on any ancestor). Changes the glyph only — the hit area follows --height.
--chevron-iconCustom property
Chevron glyph as a url(). Masked, so its color comes from the control, not the image.
--clear-iconCustom property
Clear button glyph as a url().
--border-radiusCustom property
Trigger + panel radius.
--backgroundCustom property
Panel background.