Hoppa till innehåll

Komponenter

Välj

En rullgardinslista för att välja bland flera alternativ.

Användning

Grundläggande

HTML
<bs:bsui-select placeholder="Pick a region">
  <bs:bsui-select-trigger />
  <bs:bsui-select-popup>
    <bs:bsui-select-option value="eu" label="Europe" />
    <bs:bsui-select-option value="us" label="United States" />
    <bs:bsui-select-option value="ap" label="Asia Pacific" />
  </bs:bsui-select-popup>
</bs:bsui-select>

Flera

Flera värden samtidigt visas i utlösaren allteftersom de väljs.

HTML
<bs:bsui-select multiple="true" name="stack" placeholder="Pick your stack">
  <bs:bsui-select-trigger />
  <bs:bsui-select-popup>
    <bs:bsui-select-option value="wordpress" label="WordPress" />
    <bs:bsui-select-option value="laravel" label="Laravel" />
    <bs:bsui-select-option value="astro" label="Astro" />
    <bs:bsui-select-option value="rails" label="Rails" />
  </bs:bsui-select-popup>
</bs:bsui-select>

Otillgängligt alternativ

Gruppen skickar pro tills någon ändrar det, och enterprise är synligt men kan inte väljas.

HTML
<bs:bsui-select name="plan" defaultValue="pro" placeholder="Pick a plan">
  <bs:bsui-select-trigger />
  <bs:bsui-select-popup>
    <bs:bsui-select-option value="free" label="Free" />
    <bs:bsui-select-option value="pro" label="Pro" />
    <bs:bsui-select-option value="enterprise" label="Enterprise, contact sales" disabled="true" />
  </bs:bsui-select-popup>
</bs:bsui-select>

I ett fält

Felmeddelandet hör till fältet, så själva väljaren förblir oförändrad.

Pick the region your data has to stay in.
HTML
<bs:bsui-field invalid="true">
  <bs:bsui-field-label text="Region" />
  <bs:bsui-select name="region" placeholder="Pick a region">
    <bs:bsui-select-trigger />
    <bs:bsui-select-popup>
      <bs:bsui-select-option value="eu" label="Europe" />
      <bs:bsui-select-option value="us" label="United States" />
    </bs:bsui-select-popup>
  </bs:bsui-select>
  <bs:bsui-field-error text="Pick the region your data has to stay in." />
</bs:bsui-field>

Struktur

Välj består av blocken nedan. Varje block är ett separat block som bara renderas inuti sin förälder.

  • bsui/select
  • bsui/select-popup
  • bsui/select-option
  • bsui/select-trigger

Attribut

AttributTypStandard
defaultValue text —
multiple toggle false
name text —
placeholder text Select...
nameAlt text —
onChange text —
value text —
options text —

bsui/select-popup

Det här blocket har inga attribut.

bsui/select-option

AttributTypStandard
value text —
label text —
disabled toggle false

bsui/select-trigger

Det här blocket har inga attribut.