Select
The Select input component uses HTML's native select input. Select inputs can be single value selections, or multi-value selections by using the multiple attribute.
Use it with the Field component to access all the functionalities.
Examples
Base
Show code
<section>
<o-field label="Required">
<o-select placeholder="Select a name" required>
<option value="flint">Flint</option>
<option value="silver">Silver</option>
<option value="vane">Vane</option>
<option value="billy">Billy</option>
</o-select>
</o-field>
<o-field label="Rounded">
<o-select placeholder="Select a character" rounded>
<option value="flint">Flint</option>
<option value="silver">Silver</option>
<option value="vane">Vane</option>
<option value="billy">Billy</option>
</o-select>
</o-field>
<o-field
label="Error"
variant="danger"
message="Something went wrong with this field">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
<option value="vane">Vane</option>
<option value="billy">Billy</option>
</o-select>
</o-field>
<o-field label="Disabled">
<o-select placeholder="Select a character" disabled>
<option value="flint">Flint</option>
<option value="silver">Silver</option>
<option value="vane">Vane</option>
<option value="billy">Billy</option>
</o-select>
</o-field>
<o-field label="Disabled options">
<o-select placeholder="Select a character">
<option value="flint" disabled>Flint</option>
<option value="silver" disabled>Silver</option>
</o-select>
</o-field>
<o-field label="Expanded">
<o-select placeholder="Select a character" expanded>
<option value="flint">Flint</option>
<option value="silver">Silver</option>
<option value="vane">Vane</option>
<option value="billy" disabled>Billy</option>
</o-select>
</o-field>
</section>
Options
There are several ways to provide options for a select input:
- An array of primitives
['A', 'B', 'C'] - An object literal with key-value pairs
{ a: 'A', b: 'B', c: 'C' } - An array of objects with
labelandvalueproperties - Using the native
<option>tags directly inside the default template slot.
TypeScript
The options property type is defined by the SelectOptions type.
Array of primitives
The simplest way to provide options is an array of primitives like strings or numbers, where the primitive will be used for both the string casted label representation and the value of the option.
Show code
<section>
<o-select
placeholder="Select a character"
expanded
icon="user"
:options="[
'Tyrion Lannister',
'Jamie Lannister',
'Daenerys Targaryen',
'Jon Snow',
]" />
</section>
Key-Value pair object
You may also provide the options prop where the keys are values and the values of each property are labels.
Show code
<section>
<o-select
placeholder="Select a character"
expanded
icon="user"
:options="{
heisenberg: 'Heisenberg',
jesse: 'Jesse',
saul: 'Saul',
mike: 'Mike',
jack: 'Jack',
}" />
</section>
Array of objects
The most flexible way to define options is to provide an array of objects. The object is defined as:{ value: any, label: string }
The value attribute is the real value which will be used by the v-model property and other events. The label attribute is the visible representation of the option. The object can be extended by additional attribute, which will be applied to the option item tag.
Show code
<section>
<o-select
placeholder="Select a character"
expanded
icon="user"
:options="[
{ label: 'Flint', value: 'flint' },
{ label: 'Silver', value: 'silver' },
{ label: 'Vane', value: 'vane' },
{ label: 'Billy', value: 'billy' },
{
label: 'Jack',
value: 'jack',
disabled: true,
},
]" />
</section>
Grouped options
Using the array of objects syntax you can also create grouped options (<optgroup> in HTML) by adding an options property to the object option.
Show code
<section>
<o-select
v-model="selected"
placeholder="Select a character"
aria-label="Select a character"
icon="user"
expanded
:options="[
{
label: 'Names',
options: ['Flint', 'Silver', 'Vane', 'Jack'],
},
{
label: 'Numbers',
options: [1, 2, 3],
},
]" />
<p><b>Selected:</b> {{ selected }}</p>
</section>
import { ref } from "vue";
const selected = ref<string>("");
Default Slot
Sometimes it may be desirable to manually output the contents of a select list in order to create specialized structures. This can be done by using the default slot to explicitly output your options like the native HTML select element.
Show code
<section>
<o-select placeholder="Select a planet" expanded>
<optgroup label="Inner Planets">
<option value="mercury">Mercury</option>
<option value="venus">Venus</option>
<option value="earth">Earth</option>
<option value="mars">Mars</option>
</optgroup>
<optgroup label="Outer planets">
<option value="jupiter">Jupiter</option>
<option value="saturn">Saturn</option>
<option value="uranus">Uranus</option>
<option value="neptune">Neptune</option>
</optgroup>
</o-select>
</section>
Multiple
The input also supports a multiple attribute that allows multi-selection. When used the v-model attribute will be an array of values.
Accessibility Notes
Select inputs with the multiple attribute can be challenging for some users because they require holding-down the control or command keys to perform multiple selections. Depending on your audience, you may want to consider using a checkbox input instead.
Show code
<section>
<o-field label="Multiple">
<o-select v-model="selected" multiple native-size="8">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
<option value="vane">Vane</option>
<option value="billy">Billy</option>
<option value="jack">Jack</option>
<option value="heisenberg">Heisenberg</option>
<option value="jesse">Jesse</option>
<option value="saul">Saul</option>
<option value="mike">Mike</option>
</o-select>
</o-field>
<p><b>Selected:</b> {{ selected }}</p>
</section>
import { ref } from "vue";
const selected = ref<string[]>([]);
Sizes
The component can be displayed in different sizes using the size prop.
Show code
<section>
<o-field label="Small">
<o-select placeholder="Select a character" size="small">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Default">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Medium">
<o-select placeholder="Select a character" size="medium">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Large">
<o-select placeholder="Select a character" size="large">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
</section>
Variants
Different styles can be achieved with the variant prop.
Show code
<section>
<o-field label="Primary" variant="primary">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Secondary" variant="secondary">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Success" variant="success">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Info" variant="info">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Warning" variant="warning">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field label="Danger" variant="danger">
<o-select placeholder="Select a character">
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
</section>
With Icons
Add an icon to the component to explain its function more visually.
Show code
<section>
<o-field>
<o-select
placeholder="Select a name"
aria-label="Select a name"
icon="search"
icon-clickable>
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
<o-field>
<o-select
placeholder="Select a name"
aria-label="Select a name"
icon="envelope"
icon-right="times-circle"
icon-right-clickable>
<option value="flint">Flint</option>
<option value="silver">Silver</option>
</o-select>
</o-field>
</section>
Select Component
Select an item in a list. Use with Field to access all functionalities.
<o-select></o-select>Props
| Prop name | Description | Type | Values | Default |
|---|---|---|---|---|
| aria-activedescendant | Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application. | string | - | |
| aria-atomic | Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute. | Booleanish | - | |
| aria-autocomplete | Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made. | "both" | "inline" | "list" | "none" | - | |
| aria-busy | Indicates an element is being modified and that assistive technologies MAY want to wait until the modifications are complete before exposing them to the user. | Booleanish | - | |
| aria-checked | Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. | "mixed" | Booleanish | - | |
| aria-colcount | Defines the total number of columns in a table, grid, or treegrid. | Numberish | - | |
| aria-colindex | Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. | Numberish | - | |
| aria-colspan | Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. | Numberish | - | |
| aria-controls | Identifies the element (or elements) whose contents or presence are controlled by the current element. | string | - | |
| aria-current | Indicates the element that represents the current item within a container or set of related elements. | "date" | "location" | "page" | "step" | "time" | Booleanish | - | |
| aria-describedby | Identifies the element (or elements) that describes the object. | string | - | |
| aria-details | Identifies the element that provides a detailed, extended description for the object. | string | - | |
| aria-disabled | Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. | Booleanish | - | |
deprecated - in ARIA 1.1 | "copy" | "execute" | "link" | "move" | "none" | "popup" | - | ||
| aria-errormessage | Identifies the element that provides an error message for the object. | string | - | |
| aria-expanded | Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed. | Booleanish | - | |
| aria-flowto | Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order. | string | - | |
deprecated - in ARIA 1.1 | Booleanish | - | ||
| aria-haspopup | Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. | "dialog" | "grid" | "listbox" | "menu" | "tree" | Booleanish | - | |
| aria-hidden | Indicates whether the element is exposed to an accessibility API. | Booleanish | - | |
| aria-invalid | Indicates the entered value does not conform to the format expected by the application. | "grammar" | "spelling" | Booleanish | - | |
| aria-keyshortcuts | Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element. | string | - | |
| aria-label | Defines a string value that labels the current element. | string | - | |
| aria-labelledby | Identifies the element (or elements) that labels the current element. | string | - | |
| aria-level | Defines the hierarchical level of an element within a structure. | Numberish | - | |
| aria-live | Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region. | "assertive" | "off" | "polite" | - | |
| aria-modal | Indicates whether an element is modal when displayed. | Booleanish | - | |
| aria-multiline | Indicates whether a text box accepts multiple lines of input or only a single line. | Booleanish | - | |
| aria-multiselectable | Indicates that the user may select more than one item from the current selectable descendants. | Booleanish | - | |
| aria-orientation | Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous. | "horizontal" | "vertical" | - | |
| aria-owns | Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. | string | - | |
| aria-placeholder | Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format. | string | - | |
| aria-posinset | Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. | Numberish | - | |
| aria-pressed | Indicates the current "pressed" state of toggle buttons. | "mixed" | Booleanish | - | |
| aria-readonly | Indicates that the element is not editable, but is otherwise operable. | Booleanish | - | |
| aria-relevant | Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. | "additions removals" | "additions text" | "additions" | "all" | "removals additions" | "removals text" | "removals" | "text additions" | "text removals" | "text" | - | |
| aria-required | Indicates that user input is required on the element before a form may be submitted. | Booleanish | - | |
| aria-roledescription | Defines a human-readable, author-localized description for the role of an element. | string | - | |
| aria-rowcount | Defines the total number of rows in a table, grid, or treegrid. | Numberish | - | |
| aria-rowindex | Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. | Numberish | - | |
| aria-rowspan | Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. | Numberish | - | |
| aria-selected | Indicates the current "selected" state of various widgets. | Booleanish | - | |
| aria-setsize | Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. | Numberish | - | |
| aria-sort | Indicates if items in a table or grid are sorted in ascending or descending order. | "ascending" | "descending" | "none" | "other" | - | |
| aria-valuemax | Defines the maximum allowed value for a range widget. | Numberish | - | |
| aria-valuemin | Defines the minimum allowed value for a range widget. | Numberish | - | |
| aria-valuenow | Defines the current value for a range widget. | Numberish | - | |
| aria-valuetext | Defines the human readable text alternative of aria-valuenow for a range widget. | string | - | |
| autocomplete | Native options to use in HTML5 validation, whether the value of the form's controls can be automatically completed by the browser. | string | - | From config: select: { |
| customValidity | Custom HTML 5 validation error to set on the form control | string | ((currentValue: ValueType<unknown, IsMultiple> | null , state: ValidityState) => string) | undefined | - | "" |
| disabled | Same as native disabled | boolean | - | false |
| expanded | Makes input full width when inside a grouped or addon field | boolean | - | From config: select: { |
| form | Same as native form | string | - | |
| icon | Icon to be shown | string | - | From config: select: { |
| iconClickable | Makes the icon clickable | boolean | - | false |
| iconPack | Icon pack to use | string | mdi, fa, fas and any other custom icon pack | From config: select: { |
| iconRight | Icon to be added on the right side | string | - | From config: select: { |
| iconRightClickable | Make the icon right clickable | boolean | - | false |
| iconRightVariant | Variant of right icon | string | - | |
| id | Same as native id. Also set the for label for o-field wrapper - default is an uuid. | string | - | useId() |
| v-model | The input value state, use v-model to make it two-way binding | ValueType<unknown, IsMultiple> | - | |
| multiple | Allow multiple selection - converts the modelValue into an array | IsMultiple | - | |
| name | Same as native name | string | - | |
| nativeSize | Same as native size | Numberish | - | |
| options | Select options, unnecessary when default slot is used | SelectOptions<unknown> | - | |
| override | Override existing theme classes completely | boolean | - | |
| placeholder | Text when nothing is selected | string | - | |
| required | Same as native required | Booleanish | - | |
| rounded | Makes the element rounded | boolean | - | false |
| size | Vertical size of input | string | small, medium, large | From config: select: { |
| statusIcon | Show status icon using field and variant prop | boolean | - | From config: { |
| useHtml5Validation | Enable HTML 5 native validation | boolean | - | From config: { |
| variant | Color variant of the control | string | primary, info, success, warning, danger, and any other custom color | From config: select: { |
Events
| Event name | Properties | Description |
|---|---|---|
| update:model-value | value unknown | unknown[] - updated modelValue prop | modelValue prop two-way binding |
| focus | event Event - native event | on input focus event |
| blur | event Event - native event | on input blur event |
| invalid | event Event - native event | on input invalid event |
| icon-click | event Event - native event | on icon click event |
| icon-right-click | event Event - native event | on icon right click event |
Slots
| Name | Description | Bindings |
|---|---|---|
| placeholder | Override the placeholder | |
| default | Define the select options here, default is options prop |
Class Inspector
| Class prop | Description | Props | Suffixes | |
|---|---|---|---|---|
| rootClass | Class of the root element. | |||
| sizeClass | Class of the root element with size. | size | small | |
| variantClass | Class of the root element with variant. | variant | primary | |
| expandedClass | Class of the root element when expanded. | expanded | ||
| disabledClass | Class of the root element when disabled. | disabled | ||
| roundedClass | Class of the root element when rounded. | rounded | ||
| hasIconRightClass | Class to the root element when a right icon is used. | iconRight | ||
| multipleClass | Class of the root element when multiple. | multiple | ||
| selectClass | Class of the native select element. | |||
| placeholderClass | Class of the native select element with a placeholder. | |||
| arrowedClass | Class of the native select element with an arrow. 👉 It applies the arrow icon using background-image and background-position on select element. An alternative to override this is the iconRight prop (globally or not). | |||
| iconLeftSpaceClass | Class of the native select element with left icon space. | icon | ||
| iconRightSpaceClass | Class of the native select element with right icon space. | iconRight | ||
| iconLeftClass | Class of the left icon element. | icon | ||
| iconRightClass | Class of the right icon element. | iconRight |
Sass Variables
Current theme ➜ Oruga
| SASS Variable | Default |
|---|---|
| $select-height | h.useVar("control-height") |
| $select-padding | h.useVar("control-padding-vertical") h.useVar("control-padding-horizontal") |
| $select-disabled-opacity | h.useVar("control-disabled-opacity") |
| $select-color | h.useVar("font-color") |
| $select-font-size | h.useVar("font-size") |
| $select-font-weight | h.useVar("font-weight") |
| $select-line-height | h.useVar("line-height") |
| $select-box-shadow | h.useVar("control-box-shadow-inset") |
| $select-background-color | h.useVar("control-background-color") |
| $select-border-color | h.useVar("control-border-color") |
| $select-border-style | solid |
| $select-border-width | h.useVar("control-border-width") |
| $select-border-radius | h.useVar("border-radius") |
| $select-border-radius-rounded | h.useVar("border-radius-rounded") |
| $select-multiple-padding | h.useVar("control-spacer") |
| $select-arrow-color | vars.$font-color |
| $select-arrow-size | 1em |
See ➜ 📄 SCSS file
Current theme ➜ Bulma
The theme does not have any custom variables for this component.
Current theme ➜ Bootstrap
The theme does not have any custom variables for this component.
