跳转到正文

组件

选择

用于从选项列表中进行选择的下拉菜单。

用法

基础

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>

多选

一次选择多个值,并在选中时将它们列在触发器中。

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>

不可用选项

表单会提交 pro,直到有人更改它;enterprise 会显示出来,但无法选择。

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>

位于字段中

错误消息附在字段上,因此选择框本身保持不变。

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>

结构

选择由以下区块组成。每个区块都是独立的区块,只会在其父级内部渲染。

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

属性

属性类型默认
defaultValue text —
multiple toggle false
name text —
placeholder text Select...
nameAlt text —
onChange text —
value text —
options text —

bsui/select-popup

此区块不接受任何属性。

bsui/select-option

属性类型默认
value text —
label text —
disabled toggle false

bsui/select-trigger

此区块不接受任何属性。