Skip to content

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 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.

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.

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.

Dropdowns are very versatile, can used as a quick menu or even like a select for discoverable content.

html
<o-dropdown></o-dropdown>

Props

Prop nameDescriptionTypeValuesDefault
activeThe active state of the dropdown, use v-model:active to make it two-way bindingboolean-false
animationCustom animation (transition name)string-
From config:
dropdown: {
  animation: "fade"
}
ariaLabelAccessibility aria-label to be passed to the trigger element - usefull if selectablestring-
checkScrollMakes the component check if menu reached scroll start or end and emit scroll eventsboolean-
From config:
dropdown: {
  checkScroll: false
}
clipScrollSet 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: {
  clipScroll: false
}
closeOnOutsideClose Dropdown when clicked outsideboolean-
From config:
dropdown: {
  closeOnOutside: true
}
closeOnScrollClose Dropdown when page get scrolledboolean-
From config:
dropdown: {
  closeOnScroll: false
}
delayDropdown delay before it appears (number in ms)number-
desktopModalDropdown content (items) are shown into a modal on desktopboolean-
From config:
dropdown: {
  desktopModal: false
}
disabledDropdown is disabledboolean-false
expandedDropdown will be expanded (full-width)boolean-false
inlineDropdown content (items) are shown inline, trigger is removedboolean-false
keepFirstThe first option will always be pre-selected (easier to just hit enter or tab)boolean-
From config:
dropdown: {
  keepFirst: false
}
keepOpenKeep dropdown list open when item get selectedboolean-
From config:
dropdown: {
  keepOpen: false
}
labelTrigger label, unnecessary when trgger slot is usedstring-
labelledbyEnsures that each input has an accessible name.string-
maxHeightMax height of dropdown contentnumber | string-
From config:
dropdown: {
  maxHeight: 200
}
menuIdHTML element Id of the dropdown menu elementstring-useId()
menuTagDropdown menu tag nameDynamicComponent-
From config:
dropdown: {
  menuTag: "div"
}
mobileBreakpointMobile breakpoint as max-width valuestring-
From config:
dropdown: {
  mobileBreakpoint: undefined
}
mobileModalDropdown content (items) are shown into a modal on mobileboolean-
From config:
dropdown: {
  mobileModal: true
}
v-modelThe selected option valueunknown-
multipleAllows multiple selections - converts the modelValue into an arrayboolean-
optionsDropdown options, unnecessary when default slot is usedOptionsPropWithGroups<unknown>-
overrideOverride existing theme classes completelyboolean-
positionPosition 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: {
  position: "bottom-left"
}
scrollableDropdown content will be scrollableboolean-false
selectOnCloseSelect current focused item when closedboolean-
From config:
dropdown: {
  selectOnClose: false
}
selectOnFocusSelect current focused item when focusedboolean-
From config:
dropdown: {
  selectOnFocus: false
}
selectableEnables item selectionboolean-false
teleportAppend 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: {
  teleport: false
}
triggerTagDropdown trigger tag nameDynamicComponent-
From config:
dropdown: {
  triggerTag: "div"
}
triggersDropdown will be triggered by any events("click" | "contextmenu" | "focus" | "keydown" | "hover")[]click, hover, contextmenu, focus
From config:
dropdown: {
  triggers: ["click"]
}

Events

Event namePropertiesDescription
update:model-valuevalue T | T[] - updated modelValue propmodelValue prop two-way binding
update:activevalue boolean - updated active propactive prop two-way binding
selectvalue T - selected valueon select event - fired before update:modelValue
changevalue T | T[] - selected value
openmethod string - open method
event Event - native event
on open event
closemethod string - close method
event Event - native event
on close event
scroll-startthe list inside the dropdown reached the start
scroll-endthe list inside the dropdown reached it's end

Slots

NameDescriptionBindings
triggerOverride the trigger element, default is label propactive boolean - dropdown active state
value T | T[] - the selected value
toggle () =&gt; void - toggle dropdown active state
defaultPlace dropdown items hereactive boolean - dropdown active state

toggle () =&gt; void - toggle dropdown active state
beforePlace extra o-dropdown-item components here, even if you have some options defined by prop
groupOverride the option groupgroup object - options group
index number - option index
afterPlace extra o-dropdown-item components here, even if you have some options defined by prop

An option item used by the dropdown component.

html
<o-dropdown-item></o-dropdown-item>

Props

Prop nameDescriptionTypeValuesDefault
clickableItem is clickable and emit an eventboolean-true
disabledItem is disabledboolean-false
hiddenDefine whether the item is visible or notboolean-false
labelItem label, unnecessary when default slot is usedstring-
overrideOverride existing theme classes completelyboolean-
tagDropdown item tag nameDynamicComponent-
From config:
dropdown: {
  itemTag: "div"
}
valueItem value (it will be used as v-model of wrapper component) - default is an uuidstring|number|object-

Events

Event namePropertiesDescription
clickvalue string | number | object - value prop data
event event - Native Event
onclick event

Slots

NameDescriptionBindings
defaultOverride the label, default is label prop

Class Inspector

Classes applied to the element:
Class propDescriptionPropsSuffixes
rootClassClass of the root element.
mobileClassClass of the root element when on mobile.
👉 Switch to mobile view to see it in action!
modalClassClass of the root element when shown as modal.mobileModal
desktopModal
teleportClassClass of the root element when teleported.teleport
disabledClassClass of the root element when disabled.disabled
inlineClassClass of the root element when inlined.inline
expandedClassClass of the root element when expanded.expanded
activeClassClass of the root element when active or inline.active
inline
hoverableClassClass of the root element when trigger is hoverable.triggers
positionClassClass of the root element with postion.positionauto
top
bottom
left
right
top-right
top-left
bottom-left
bottom-right
auto
top
bottom
left
right
top-right
top-left
bottom-left
bottom-right
triggerClassClass of the trigger element.
overlayClassClass of the overlay element when shown as modal.mobileModal
desktopModal
menuClassClass of the menu element.
menuActiveClassClass of the menu element when active or inline.inline
active
menuPositionClassClass of the menu element with position.positionauto
top
bottom
left
right
top-right
top-left
bottom-left
bottom-right
auto
top
bottom
left
right
top-right
top-left
bottom-left
bottom-right
itemClassClass of the item element.
itemSelectedClassClass of the item element when selected.
itemDisabledClassClass of the item element when disabled.disabled
itemClickableClassClass of the item element when clickable.clickable
itemFocusedClassClass of the item element when focused.
scrollClipClassClass of the body when is open and scroll is clipped.clipScroll
scrollKeepClassClass of the body when is open and scroll is keeped.clipScroll

Sass variables

Current theme ➜ Oruga

SASS VariableDefault
$dropdown-disabled-opacityvar(--#{$prefix}base-disabled-opacity)
$dropdown-item-active-background-colorvar(--#{$prefix}primary)
$dropdown-item-active-colorvar(--#{$prefix}primary-invert)
$dropdown-item-color#000000
$dropdown-item-disabled-opacityvar( --#{$prefix}base-disabled-opacity)
$dropdown-item-font-sizevar(--#{$prefix}base-font-size)
$dropdown-item-hover-background-color#f5f5f5
$dropdown-item-hover-color#000000
$dropdown-item-line-heightvar(--#{$prefix}base-line-height)
$dropdown-item-padding0.375rem 1rem
$dropdown-item-font-weight400
$dropdown-menu-background#ffffff
$dropdown-menu-border-radiusvar(--#{$prefix}base-border-radius)
$dropdown-menu-box-shadow0 0.5em 1em -0.125em rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.02)
$dropdown-menu-spacer0px
$dropdown-menu-margin0
$dropdown-menu-padding0.5rem 0 0.5rem 0
$dropdown-menu-width12rem
$dropdown-menu-zindex50
$dropdown-mobile-max-heightcalc(100vh - 120px)
$dropdown-mobile-max-width460px
$dropdown-mobile-overlay-colorrgba(#000000, 0.86)
$dropdown-mobile-overlay-zindex55
$dropdown-mobile-widthcalc(100vw - 40px)
$dropdown-mobile-zindex60

See ➜ 📄 Full scss file

Current theme ➜ Bulma

SASS VariableDefault
$dropdown-content-max-height200px
$dropdown-disabled-opacity0.5
$dropdown-gap0px
$dropdown-z40
$dropdown-mobile-breakpointiv.$desktop
$dropdown-background-background-colorhsla( #{css.getVar("scheme-h")}, #{css.getVar("scheme-s")}, #{css.getVar("scheme-invert-l")}, 0.86)
$dropdown-modal-width75%
$dropdown-modal-min-width25%
$dropdown-modal-max-widthcalc(100vw - 40px)

See ➜ 📄 Full scss file

Current theme ➜ Bootstrap

SASS VariableDefault
$dropdown-modal-menu-zindex$zindex-modal
$dropdown-modal-backdrop-zindex$zindex-modal-backdrop
$dropdown-modal-width75%
$dropdown-modal-min-width25%
$dropdown-modal-max-widthcalc(100vw - 40px)

See ➜ 📄 Full scss file

Released under the MIT License.