Skip to content

Listbox

experimental

The Listbox component presents a list of options and allows a user to select one or more of them. The component uses the ARIA listbox role and implements the W3C ARIA APG Listbox Pattern. Combine it with the Field component to access all functionalities.

Examples

Base

Listboxes are great and accessible select menus for your app, complete with robust support for keyboard navigation and, unlike HTML <select> elements, may contain images. The v-model can be used to bind the selected value. By default the component allows a single option to be chosen.

Accessibility Note:

When assistive technologies present a listbox, the name of an option is calculated by the browser as a flat string. Therefore, the content of an option should not contain any semantic information, such as a heading. In addition, assistive technologies does not provide an accessible way to present a list of interactive elements for the listbox role, such as links, buttons, or checkboxes.

Multiple

When the multiple prop is used, the component become a multi-select listbox that allows multiple options to be selected. The v-model now contains a list of all selected items.

Options

Instead of using the <o-list-item> component directly inside the default slot, an options prop can be defined, which can be used to specify the options programmatically. It accepts several different formats of values:

  • 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
  • Grouped options by adding additional options to the option object.

Note

The options prop works the same as the Select input component options prop.

Filterable

The component provides a built-in filtering feature, which can be enabled by adding the filterable property. A custom filter function can be defined using the filter property. By default, a lowercased label string comparison is performed.

Slots

A custom header and footer can be added before and after the options list by using the header and footer slots. You can also display content, when no options are visible, either because there are no options or because they are hidden through filtering, using the empty slot.

Infinite Scroll & Async Data

When having to many options, consider adding a max height using the scrollHeight property, which allows to cap the list at a fixed max-height. This will render a long list of options with a scrollbar. The component will emit a scroll-start or scroll-end event, when the top or bottom of the list is reached. These events can be used to load more options as needed. Consider adding backend-filtering when updating options manually in response to changes in the filter value.

Listbox Component

Listbox is used to select one or more values from a list of items.

html
<o-listbox></o-listbox>

Props

Prop nameDescriptionTypeValuesDefault
animationCustom animation (transition name)string-
From config:
listbox: {
  animation: "fade"
}
ariaLabelDefines a string value that labels an interactive element.string-
ariaLabelledbyIdentifier of the underlying input element.string-
backendFilteringItems won't be filtered on clientside, use the filter event to filter in your backendboolean-false
disabledInteraction is disabledboolean-false
emptyLabelA label which is displayed when no options are visiblestring-
From config:
listbox: {
  emptyLabel: undefined
}
filterCustom filter function to filter the items based on the input value - default is label string comparison((option: unknown, value: string) => boolean)-
filterDebounceNumber of milliseconds to delay the filter eventnumber-
From config:
listbox: {
  filterDebounce: 400
}
filterIconIcon of the column search inputstring-
From config:
listbox: {
  filterIcon: undefined
}
filterPlaceholderPlaceholder of the column search inputstring-
From config:
listbox: {
  filterPlaceholder: undefined
}
filterableEnable an additional searchbar below the headerboolean-false
iconPackIcon pack to usestringmdi, fa, fas and any other custom icon pack
From config:
listbox: {
  iconPack: undefined
}
idSame as native id. Also pass the id to an wrapping o-field component - default is an uuid.string-useId()
v-modelThe selected option value, use v-model to make it two-way bindingstring|number|object-
multipleAllows multiple selections - converts the modelValue into an arrayboolean-
optionsAutocomplete optionsOptionsPropWithGroups<unknown>-
overrideOverride existing theme classes completelyboolean-
scrollHeightHeight of the listbox, a scrollbar is defined if height of list exceeds this valuenumber | string-
From config:
listbox: {
  scrollHeight: "225"
}
selectOnFocusSelect current focused item when focusedboolean-false
selectableEnables item selectionboolean-true

Events

Event namePropertiesDescription
update:model-valuevalue unknown | unknown[] - updated modelValue propmodelValue prop two-way binding
selectvalue unknown - selected valueon select event - fired before update:modelValue
filtervalue string - filter value
event Event - native event
on filter change event
focusevent Event - native eventon list focus event
blurevent Event - native eventon list blur event
scroll-startscrolling inside the list reached the start
scroll-endscrolling inside the list reached the end

Slots

NameDescriptionBindings
headerDefine an additional header
filterOverridet the filter inputvalue string - filter input value
onChange (input: string, event: Event): void - on filter input change event
onKeydown (event: Event): void - on filter input keydown event
defaultDefine the listbox items here
emptyDefine the content to show if the list is empty
footerDefine an additional footer

ListItem Component

An option item used by the listbox component.

html
<o-list-item></o-list-item>

Props

Prop nameDescriptionTypeValuesDefault
ariaLabelDefines a string value that labels an interactive element.string-
ariaLabelledbyIdentifier of the underlying input element.string-
disabledItem is disabledboolean-false
hiddenDefine whether the item is visible or notboolean-false
iconIcon to be shownstring-
iconPackIcon pack to usestringmdi, fa, fas and any other custom icon pack
From config:
listbox: {
  iconPack: undefined
}
iconSizeIcon sizestringsmall, medium, large
From config:
listbox: {
  iconSize: undefined
}
labelItem label, unnecessary when default slot is usedstring-
overrideOverride existing theme classes completelyboolean-
valueItem value (it will be used as v-model of wrapper component) - default is an uuidstring|number|object-useId()

Events

Event namePropertiesDescription
clickvalue unknown - value prop data
event event - native event
onclick event

Slots

NameDescriptionBindings
defaultOverride the label, default is label propselected boolean - item is selected
disabled boolean - item is disabled

Class Inspector

Classes applied to the element:
Want to know how does the Class Inspector work?
Class propDescriptionPropsSuffixes
rootClass
Class of the root element.
disabledClass
Class of the root element when disabled.
disabled
selectableClass
Class of the root element when selectable.
selectable
filterableClass
Class of the root element when filterable.
filterable
multipleClass
Class of the root element when multiple.
multiple
headerClass
Class of the header slot wrapper element.
footerClass
Class of the footer slot wrapper element.
emptyClass
Class of the empty slot wrapper element.
filterClass
Class of the filter wrapper element.
listClass
Class of the list element.
itemClass
Class of the item element.
itemSelectableClass
Class of the item element when is selectable.
itemSelectedClass
Class of the item element when is selected.
itemFocusedClass
Class of the item element when is focused.
itemDisabledClass
Class of the item element when is disabled.
inputClasses
Classes to apply on the internal input component.
More details here.

Sass Variables

Current theme ➜ Oruga

SASS VariableDefault
$listbox-disabled-opacityh.useVar("control-disabled-opacity")
$listbox-box-shadow0 0.5em 1em -0.125em rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.02)
$listbox-background-colorh.useVar("control-brackground-color")
$listbox-border-colorh.useVar("control-border-color")
$listbox-border-stylesolid
$listbox-border-widthh.useVar("control-border-width")
$listbox-border-radiush.useVar("border-radius")
$listbox-item-paddingh.useVar("control-spacer") calc(h.useVar("control-spacer") * 2)
$listbox-item-colorh.useVar("font-color")
$listbox-item-font-sizeh.useVar("font-size")
$listbox-item-font-weighth.useVar("font-weight")
$listbox-item-line-heighth.useVar("line-height")
$listbox-item-background-colortransparent
$listbox-item-active-colorh.useVar("primary-invert")
$listbox-item-active-background-colorh.useVar("primary")
$listbox-item-hover-background-colorh.useVar("grey-lighter")
$listbox-item-hover-colorh.useVar("font-color")

See ➜ 📄 SCSS file

Current theme ➜ Bulma

SASS VariableDefault
$listbox-disabled-opacity0.5
$listbox-item-hover-background-colorcss.getVar( "panel-block-hover-background-color")
$listbox-item-active-background-colorcss.getVar("primary")

See ➜ 📄 SCSS file

Current theme ➜ Bootstrap

SASS VariableDefault

See ➜ 📄 SCSS file

Released under the MIT License.