Skip to content

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

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 label and value properties
  • Using the native <option> tags directly inside the default slot.

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 thestring casted label representation and the value of the option.

Key-Value pair object

You may also provide the options prop where the keys are values and the values of each property are labels.

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, attrs?: object }
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 attrs attribute is an object for additional attributes, which will be applied to the option item tag.

Option groups

Using the array of objects syntax you can also create grouped options (<optgroup> in HTML) by adding an options property to the object option.

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.

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.

Sizes

The component can be displayed in different sizes using the size prop.

Variants

Different styles can be achieved with the variant prop.

With Icons

Add an icon to the component to explain its function more visually.

Select component

Select an item in a list. Use with Field to access all functionalities.

html
<o-select></o-select>

Props

Prop nameDescriptionTypeValuesDefault
autocompleteSame as native autocomplete options to use in HTML5 validationstring-
From config:
select: {
  autocomplete: "off"
}
customValidityCustom HTML 5 validation error to set on the form controlstring | ((currentValue: unknown, state: ValidityState) => string)-
disabledDisable the input - same as native disabledboolean-false
expandedMakes input full width when inside a grouped or addon fieldboolean-false
iconIcon to be shownstring-
From config:
select: {
  icon: undefined
}
iconClickableMakes the icon clickableboolean-false
iconPackIcon pack to usestringmdi, fa, fas and any other custom icon pack
From config:
select: {
  iconPack: undefined
}
iconRightIcon to be added on the right sidestring-
From config:
select: {
  iconRight: undefined
}
iconRightClickableMake the icon right clickableboolean-false
iconRightVariantVariant of right iconstring-
idSame as native id. Also set the for label for o-field wrapper - default is an uuid.string-useId()
v-modelThe input value stateunknown-
multipleAllow multiple selection - converts the modelValue into an arrayboolean-
nativeSizeSame as native sizenumber | string-
optionsSelect options, unnecessary when default slot is usedOptionsPropWithGroups<unknown>-
overrideOverride existing theme classes completelyboolean-
placeholderText when nothing is selectedstring-
requiredSame as native requiredboolean-false
roundedMakes the element roundedboolean-false
sizeVertical size of inputstringsmall, medium, large
From config:
select: {
  size: undefined
}
statusIconShow status icon using field and variant propboolean-
From config:
{
  statusIcon: true
}
useHtml5ValidationEnable HTML 5 native validationboolean-
From config:
{
  useHtml5Validation: true
}
variantColor of the controlstringprimary, info, success, warning, danger, and any other custom color
From config:
select: {
  variant: undefined
}

Events

Event namePropertiesDescription
update:model-valuevalue T | T[] - updated modelValue propmodelValue prop two-way binding
focusevent Event - native eventon input focus event
blurevent Event - native eventon input blur event
invalidevent Event - native eventon input invalid event
icon-clickevent Event - native eventon icon click event
icon-right-clickevent Event - native eventon icon right click event

Slots

NameDescriptionBindings
placeholderOverride the placeholder
defaultOverride the options, default is options prop

Class Inspector

Classes applied to the element:
Class propDescriptionPropsSuffixes
rootClassClass of the root element.
sizeClassClass of the root element with size.sizesmall
medium
large
variantClassClass of the root element with variant.variantprimary
info
warning
danger
expandedClassClass of the root element when expanded.expanded
disabledClassClass of the root element when disabled.disabled
roundedClassClass of the root element when rounded.rounded
hasIconRightClassClass to the root element when a right icon is used.iconRight
multipleClassClass of the root element when multiple.multiple
selectClassClass of the native select element.
placeholderClassClass of the native select element with a placeholder.
arrowedClassClass 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).
iconLeftSpaceClassClass of the native select element with left icon space.icon
iconRightSpaceClassClass of the native select element with right icon space.iconRight
iconLeftClassClass of the left icon element.icon
iconRightClassClass of the right icon element.iconRight

Sass variables

Current theme ➜ Oruga

SASS VariableDefault
$select-background-color#fff
$select-border-colorvar(--#{$prefix}grey-lighter)
$select-border-stylesolid
$select-border-width1px
$select-border-radiusvar(--#{$prefix}base-border-radius)
$select-rounded-border-radiusvar( --#{$prefix}base-border-radius-rounded)
$select-box-shadow$control-box-shadow
$select-color#363636
$select-icon-zindex4
$select-height$control-height
$select-line-heightvar(--#{$prefix}base-line-height)
$select-margin0
$select-padding$control-padding-vertical $control-padding-horizontal
$select-arrow-color$select-color
$select-arrow-size1rem
$select-placeholder-opacityvar(--#{$prefix}base-disabled-opacity)

See ➜ 📄 Full 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.

Released under the MIT License.