组合框
用途
Add your combobox HTML
组合框是输入优先的。可见输入过滤列表;隐藏输入存储提交的值。
HTML 结构
<div class="combobox">Root element. Add
data-auto-highlight="true"to make the first visible option active when the list opens or filters. Adddata-format="object"to serialize selected values as objects. Adddata-filter="manual"when your app owns filtering.<input type="text" role="combobox">- The editable control. It can be a direct child, inside
.input-group, or insidedata-popoverfor popup mode. <button aria-haspopup="listbox">Optional- Opens the list from an input group or popup trigger. In popup mode, include a child with
data-valueand optionaldata-placeholderto display the selected value. <button data-clear>Optional- Clears the current selection. Put the clear icon inside the button.
<svg class="combobox-trigger-icon">Optional- Decorative trailing icon for input-style comboboxes. Replace the SVG to customize the icon.
<div data-popover>- The suggestions popup. Use
data-sideanddata-alignlike Popover; the shared runtime flips and clamps the list to the visual viewport. <div role="listbox">- The suggestions list. Add
aria-multiselectable="true"in multiple mode. The component uses that attribute to render selected chips around the input. <div role="option" data-value="...">- Selectable option. Options can contain custom HTML; use
data-labelwhen the input should display different text than the rendered content. <input type="hidden">- Submitted value. Single mode stores a string; multiple mode stores a JSON array. With
data-format="object", selected values are stored as objects.
JavaScript API
示例
多个
清除按钮
组
定制项目
无效
Select a framework to continue.
已禁用
自动高亮
当列表打开或筛选时,自动突出显示使第一个可见选项处于活动状态,因此按 Enter 键可以选择它,而无需先使用箭头。