Dropdown
The Dropdown component is very versatile and can be used as contextual overlays for displaying lists as a quick menu or even toggleable to allow users to select a value from a list of content options. Unlike native select elements, the dropdown input allows you to customize both its appearance and behavior. The component implements the W3C ARIA APG Combobox Pattern.
Examples
Base
The dropdown will be a simple unselectable menu list by default.
Triggers
The component accepts several different trigger variants, such as open on hover or open only on right click instead of left click.
Adding the teleport
prop will move the dropdown menu to the referenced DOM location instead.
Options
Instead of using the <o-dropdown-item>
component directly inside the default slot, an options
prop can be defined, which can be used to define 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
andvalue
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.
Selectable
Components with the prop selectable
will have options as a selectable list.
Adding the multiple
prop will change the modelValue
prop to an array of selected options.
Inline
Components with the inline
prop set will render the options list directly, and will not have a trigger element rendered.
Modal
The content can be opened in an modal mode either for mobile or desktop only, or for both, by adding the mobile-modal
and desktop-modal
props.
Scrollable
When having to many options, consider adding the scrollable
prop, which allows the menu to remain at a fixed height.
Position
The direction in which the dropdown menu opens can be defined by the position
prop. By default, the direction is automatically calculated from the distance to the edge of the window. Adding the teleport
prop additionally will move the dropdown menu to the referenced DOM location instead.
Dropdown component
Dropdowns are very versatile, can used as a quick menu or even like a select for discoverable content.
<o-dropdown></o-dropdown>
Props
Prop name | Description | Type | Values | Default |
---|---|---|---|---|
active | The active state of the dropdown, use v-model:active to make it two-way binding | boolean | - | false |
animation | Custom animation (transition name) | string | - | From config: dropdown: { |
ariaLabel | Accessibility aria-label to be passed to the trigger element - usefull if selectable | string | - |
|
checkScroll | Makes the component check if menu reached scroll start or end and emit scroll events | boolean | - | From config: dropdown: { |
clipScroll | Set true to remove the body scrollbar.When false , a non-scrollable scrollbar will be kept to avoid moving the background,but will set the body to a fixed position, which may break some layouts. | boolean | - | From config: dropdown: { |
closeOnOutside | Close Dropdown when clicked outside | boolean | - | From config: dropdown: { |
closeOnScroll | Close Dropdown when page get scrolled | boolean | - | From config: dropdown: { |
delay | Dropdown delay before it appears (number in ms) | number | - | |
desktopModal | Dropdown content (items) are shown into a modal on desktop | boolean | - | From config: dropdown: { |
disabled | Dropdown is disabled | boolean | - | false |
expanded | Dropdown will be expanded (full-width) | boolean | - | false |
inline | Dropdown content (items) are shown inline, trigger is removed | boolean | - | false |
keepFirst | The first option will always be pre-selected (easier to just hit enter or tab) | boolean | - | From config: dropdown: { |
keepOpen | Keep dropdown list open when item get selected | boolean | - | From config: dropdown: { |
label | Trigger label, unnecessary when trgger slot is used | string | - | |
labelledby | Ensures that each input has an accessible name. | string | - |
|
maxHeight | Max height of dropdown content | number | string | - | From config: dropdown: { |
menuId | HTML element Id of the dropdown menu element | string | - | useId() |
menuTag | Dropdown menu tag name | DynamicComponent | - | From config: dropdown: { |
mobileBreakpoint | Mobile breakpoint as max-width value | string | - | From config: dropdown: { |
mobileModal | Dropdown content (items) are shown into a modal on mobile | boolean | - | From config: dropdown: { |
v-model | The selected option value | unknown | - | |
multiple | Allows multiple selections - converts the modelValue into an array | boolean | - |
|
options | Dropdown options, unnecessary when default slot is used | OptionsPropWithGroups<unknown> | - | |
override | Override existing theme classes completely | boolean | - | |
position | Position of the dropdown relative to the trigger | "auto" | "bottom-left" | "bottom-right" | "bottom" | "left" | "right" | "top-left" | "top-right" | "top" | auto , top , bottom , left , right , top-right , top-left , bottom-left , bottom-right | From config: dropdown: { |
scrollable | Dropdown content will be scrollable | boolean | - | false |
selectOnClose | Select current focused item when closed | boolean | - | From config: dropdown: { |
selectOnFocus | Select current focused item when focused | boolean | - | From config: dropdown: { |
selectable | Enables item selection | boolean | - | false |
teleport | Append the component to another part of the DOM. Set true to append the component to the body.In addition, any CSS selector string or an actual DOM node can be used. | boolean | object | string | - | From config: dropdown: { |
triggerTag | Dropdown trigger tag name | DynamicComponent | - | From config: dropdown: { |
triggers | Dropdown will be triggered by any events | ("click" | "contextmenu" | "focus" | "keydown" | "hover")[] | click , hover , contextmenu , focus | From config: dropdown: { |
Events
Event name | Properties | Description |
---|---|---|
update:model-value | value T | T[] - updated modelValue prop | modelValue prop two-way binding |
update:active | value boolean - updated active prop | active prop two-way binding |
select | value T - selected value | on select event - fired before update:modelValue |
change | value T | T[] - selected value | |
open | method string - open methodevent Event - native event | on open event |
close | method string - close methodevent Event - native event | on close event |
scroll-start | the list inside the dropdown reached the start | |
scroll-end | the list inside the dropdown reached it's end |
Slots
Name | Description | Bindings |
---|---|---|
trigger | Override the trigger element, default is label prop | active boolean - dropdown active statevalue T | T[] - the selected valuetoggle () => void - toggle dropdown active state |
default | Place dropdown items here | active boolean - dropdown active statetoggle () => void - toggle dropdown active state |
before | Place extra o-dropdown-item components here, even if you have some options defined by prop | |
group | Override the option group | group object - options groupindex number - option index |
after | Place extra o-dropdown-item components here, even if you have some options defined by prop |
DropdownItem component
An option item used by the dropdown component.
<o-dropdown-item></o-dropdown-item>
Props
Prop name | Description | Type | Values | Default |
---|---|---|---|---|
clickable | Item is clickable and emit an event | boolean | - | true |
disabled | Item is disabled | boolean | - | false |
hidden | Define whether the item is visible or not | boolean | - | false |
label | Item label, unnecessary when default slot is used | string | - | |
override | Override existing theme classes completely | boolean | - | |
tag | Dropdown item tag name | DynamicComponent | - | From config: dropdown: { |
value | Item value (it will be used as v-model of wrapper component) - default is an uuid | string|number|object | - |
Events
Event name | Properties | Description |
---|---|---|
click | value string | number | object - value prop dataevent event - Native Event | onclick event |
Slots
Name | Description | Bindings |
---|---|---|
default | Override the label, default is label prop |
Class Inspector
Class prop | Description | Props | Suffixes | |
---|---|---|---|---|
rootClass | Class of the root element. | |||
mobileClass | Class of the root element when on mobile. 👉 Switch to mobile view to see it in action! | |||
modalClass | Class of the root element when shown as modal. | mobileModal | ||
teleportClass | Class of the root element when teleported. | teleport | ||
disabledClass | Class of the root element when disabled. | disabled | ||
inlineClass | Class of the root element when inlined. | inline | ||
expandedClass | Class of the root element when expanded. | expanded | ||
activeClass | Class of the root element when active or inline. | active | ||
hoverableClass | Class of the root element when trigger is hoverable. | triggers | ||
positionClass | Class of the root element with postion. | position | auto | |
triggerClass | Class of the trigger element. | |||
overlayClass | Class of the overlay element when shown as modal. | mobileModal | ||
menuClass | Class of the menu element. | |||
menuActiveClass | Class of the menu element when active or inline. | inline | ||
menuPositionClass | Class of the menu element with position. | position | auto | |
▷ itemClass | Class of the item element. | |||
▷ itemSelectedClass | Class of the item element when selected. | |||
▷ itemDisabledClass | Class of the item element when disabled. | disabled | ||
▷ itemClickableClass | Class of the item element when clickable. | clickable | ||
▷ itemFocusedClass | Class of the item element when focused. | |||
scrollClipClass | Class of the body when is open and scroll is clipped. | clipScroll | ||
scrollKeepClass | Class of the body when is open and scroll is keeped. | clipScroll |
Sass variables
Current theme ➜ Oruga
SASS Variable | Default |
---|---|
$dropdown-disabled-opacity | var(--#{$prefix}base-disabled-opacity) |
$dropdown-item-active-background-color | var(--#{$prefix}primary) |
$dropdown-item-active-color | var(--#{$prefix}primary-invert) |
$dropdown-item-color | #000000 |
$dropdown-item-disabled-opacity | var( --#{$prefix}base-disabled-opacity) |
$dropdown-item-font-size | var(--#{$prefix}base-font-size) |
$dropdown-item-hover-background-color | #f5f5f5 |
$dropdown-item-hover-color | #000000 |
$dropdown-item-line-height | var(--#{$prefix}base-line-height) |
$dropdown-item-padding | 0.375rem 1rem |
$dropdown-item-font-weight | 400 |
$dropdown-menu-background | #ffffff |
$dropdown-menu-border-radius | var(--#{$prefix}base-border-radius) |
$dropdown-menu-box-shadow | 0 0.5em 1em -0.125em rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.02) |
$dropdown-menu-spacer | 0px |
$dropdown-menu-margin | 0 |
$dropdown-menu-padding | 0.5rem 0 0.5rem 0 |
$dropdown-menu-width | 12rem |
$dropdown-menu-zindex | 50 |
$dropdown-mobile-max-height | calc(100vh - 120px) |
$dropdown-mobile-max-width | 460px |
$dropdown-mobile-overlay-color | rgba(#000000, 0.86) |
$dropdown-mobile-overlay-zindex | 55 |
$dropdown-mobile-width | calc(100vw - 40px) |
$dropdown-mobile-zindex | 60 |
See ➜ 📄 Full scss file
Current theme ➜ Bulma
SASS Variable | Default |
---|---|
$dropdown-content-max-height | 200px |
$dropdown-disabled-opacity | 0.5 |
$dropdown-gap | 0px |
$dropdown-z | 40 |
$dropdown-mobile-breakpoint | iv.$desktop |
$dropdown-background-background-color | hsla( #{css.getVar("scheme-h")}, #{css.getVar("scheme-s")}, #{css.getVar("scheme-invert-l")}, 0.86) |
$dropdown-modal-width | 75% |
$dropdown-modal-min-width | 25% |
$dropdown-modal-max-width | calc(100vw - 40px) |
See ➜ 📄 Full scss file
Current theme ➜ Bootstrap
SASS Variable | Default |
---|---|
$dropdown-modal-menu-zindex | $zindex-modal |
$dropdown-modal-backdrop-zindex | $zindex-modal-backdrop |
$dropdown-modal-width | 75% |
$dropdown-modal-min-width | 25% |
$dropdown-modal-max-width | calc(100vw - 40px) |
See ➜ 📄 Full scss file