Skip to content

MazDropdown

MazDropdown is a standalone dropdown menu component and versatile designed for various use cases.

Basic usage

Open dropdown with adaptive trigger

The adaptive trigger mode automatically adapts to the user's device:

  • Desktop: Uses hover behavior (mouseenter/mouseleave)
  • Mobile/Touch devices: Uses click behavior

This provides the best user experience across all devices without requiring manual configuration.

html
<MazDropdown
  :items="[
    { label: 'Action', onClick: () => toast.success('CLICKED') },
    { label: 'Link (href)', href: 'https://www.google.com', target: '_blank' },
    { label: 'Router Link', to: { name: 'index' } },
  ]"
  trigger="adaptive"
>
  Adaptive trigger
</MazDropdown>

Open dropdown only on click

html
<MazDropdown
  :items="[
    { label: 'Action', onClick: () => toast.success('CLICKED') },
    { label: 'Link (href)', href: 'https://www.google.com', target: '_blank' },
    { label: 'Router Link', to: { name: 'index' } },
  ]"
  trigger="click"
>
  Click me
</MazDropdown>

Open dropdown only on hover

html
<MazDropdown
  :items="[
    { label: 'Action', onClick: () => toast.success('CLICKED') },
    { label: 'Link (href)', href: 'https://www.google.com', target: '_blank' },
    { label: 'Router Link', to: { name: 'index' } },
  ]"
  trigger="hover"
>
  Hover me
</MazDropdown>

Custom dropdown icon

You can provide an icon to replace the default chevron icon and disable the animation

vue
<script lang="ts" setup>
  // Use vite-svg-loader to import SVG as Vue component
  import MazChevronUpDown from '@maz-ui/icons/chevron-up-down.svg?component'
</script>

<template>
  <MazDropdown
    :items="[
      { label: 'Action', onClick: () => toast.success('CLICKED') },
      { label: 'Link (href)', href: 'https://www.google.com', target: '_blank' },
      { label: 'Router Link', to: { name: 'index' } },
    ]"
    trigger="hover"
    :dropdown-icon="MazChevronUpDown"
  >
    Hover me
  </MazDropdown>

  <MazDropdown
    :items="[
      { label: 'Action', onClick: () => toast.success('CLICKED') },
      { label: 'Link (href)', href: 'https://www.google.com', target: '_blank' },
      { label: 'Router Link', to: { name: 'index' } },
    ]"
    trigger="hover"
    :dropdown-icon="MazChevronUpDown"
    :dropdown-icon-animation="false"
  >
    No icon animation
  </MazDropdown>
</template>

Custom dropdown main button without chevron icon

TIP

This component uses MazBtn has a menu button, so it inherits all its props

html
<MazDropdown
  color="primary"
  fab
  pastel
  :chevron="false"
  icon="bars-3"
  size="xl"
  :items="[
    { label: 'Action', onClick: () => toast.success('CLICKED') },
    { label: 'Link (href)', href: 'https://www.google.com', target: '_blank' },
    { label: 'Router Link', to: { name: 'index' } },
  ]"
  :close-on-click="false"
/>

Custom slots

Custom dropdown panel

You can provide a template to replace the default dropdown panel

View code
html
<MazDropdown>
  Customized dropdown panel

  <template #dropdown>
    <div class="maz-grid maz-grid-cols-3 maz-gap-2">
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
      <MazBtn color="transparent"> Item </MazBtn>
    </div>
  </template>
</MazDropdown>

Custom menuitem labels

You can provide a template to replace menuitem labels to add more elements in each menuitem

View code
html
<MazDropdown
  :items="[
    { label: 'Action', onClick: () => toast.success('CLICKED'), additionnalData: 'https://placedog.net/240/200' },
    { label: 'Link (href)', href: 'https://www.google.com', target: '_blank', additionnalData: 'https://placedog.net/340/300' },
    { label: 'Router Link', to: { name: 'index' }, additionnalData: 'https://placedog.net/440/400' },
  ]"
>
  <template #default>
    Customized labels
  </template>

  <template #menuitem-label="{ item }">
    <div class="maz-flex maz-items-center maz-gap-2">
      <MazAvatar :src="item.additionnalData" />
      <span>
        {{ item.label }}
      </span>
    </div>
  </template>
</MazDropdown>

Custom control triggered element

You can provide an HTML element or a component to replace the default button

WARNING

Add tabindex="-1" attribute to your element to avoid a double focus with Tab key

View code
html
<MazDropdown
  :items="[
    {
      label: 'Action',
      onClick: () => toast.success('CLICKED'),
      additionnalData: 'https://placedog.net/240/200',
    },
    {
      label: 'Link (href)',
      href: 'https://www.google.com',
      target: '_blank',
      additionnalData: 'https://placedog.net/340/300',
    },
    {
      label: 'Router Link',
      to: { name: 'index' },
      additionnalData: 'https://placedog.net/440/400',
    },
  ]"
>
  <template #element>
    <MazAvatar
      clickable
      hide-clickable-icon
      src="https://cdn.artphotolimited.com/images/5ff5a529bd40b83c5a537440/1000x1000/gerard-depardieu-1983.jpg"
      tabindex="-1"
    />
  </template>
</MazDropdown>

<MazDropdown
  position="top"
  :items="[
    {
      label: 'Action',
      onClick: () => toast.success('CLICKED'),
      additionnalData: 'https://placedog.net/240/200',
    },
    {
      label: 'Link (href)',
      href: 'https://www.google.com',
      target: '_blank',
      additionnalData: 'https://placedog.net/340/300',
    },
    {
      label: 'Router Link',
      to: { name: 'index' },
      additionnalData: 'https://placedog.net/440/400',
    },
  ]"
>
  <template #element="{ isOpen }">
    <button class="maz-border maz-border-solid maz-border-divider-400 maz-p-2 hover:maz-bg-surface-400" tabindex="-1">
      HTMLButtonElement: isOpen {{ isOpen }}
    </button>
  </template>
</MazDropdown>

Open programmatically

isOpen: false



vue
<template>
  <MazDropdown
    v-model="isOpen"
    :items="[
      { label: 'Action', onClick: () => toast.success('CLICKED') },
      { label: 'Link (href)', href: 'https://www.google.com', target: '_blank' },
      { label: 'Router Link', to: { name: 'index' } },
    ]"
  >
    Open
  </MazDropdown>

  <MazBtn @click="isOpen = !isOpen">
    Open Dropdown
  </MazBtn>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'

  const isOpen = ref(false)
</script>

Position

Types

MazDropdownMenuItem

ts
type MazDropdownMenuItem = {
  label: string
  onClick?: () => unknown
  target?: string
  href?: string
  to?: RouteLocationRaw
  class?: string
} & Record<string, unknown>

Props

NameDescriptionTypeRequiredDefaultPossible values
model-valuev-model
Controls whether the dropdown menu is open
booleanNofalse-
styleInline styles to apply to the component root elementHTMLAttributes['style']Noundefined-
classCSS classes to apply to the component root elementHTMLAttributes['class']Noundefined-
itemsMenu items to display in the dropdown Each item can be either a link (with href/to properties) or an action (with onClick function)
Example: [ { label: 'Profile', href: '/profile' }, { label: 'Settings', onClick: () => console.log('Settings clicked') } ]
MazDropdownMenuItem[]No[]-
idUnique identifier for the dropdown componentstringNoundefined-
triggerDetermines how the dropdown should be triggeredMazPopoverProps['trigger']Noadaptiveclick, hover, manual, adaptive
colorColor theme for the dropdown buttonMazColorNotransparentprimary, secondary, info, success, warning, destructive, transparent, contrast, accent
positionPosition of the menu relative to triggerNative typeNoautoauto, top, bottom, left, right, top-start, top-end, bottom-start, bottom-end, left-start, left-end, right-start, right-end
prefer-positionPreferred position of the menu relative to trigger when auto position is usedNative typeNobottom-startauto, top, bottom, left, right, top-start, top-end, bottom-start, bottom-end, left-start, left-end, right-start, right-end
close-on-clickControls whether the dropdown menu closes when a menu item is clickedbooleanNotrue-
disabledDisables the dropdown functionalitybooleanNofalse-
chevronControls whether to show the chevron icon in the trigger buttonbooleanNotrue-
screen-reader-descriptionAccessible description for screen readers describing the dropdown functionality If not provided, the default translation of MazUiTranslations plugin will be usedstringNoMazUiTranslationsSchema['dropdown']['screenReaderDescription']-
menu-panel-classAdditional CSS classes to apply to the dropdown menu panel Useful for customizing the dropdown appearance (background, border, etc.)HTMLAttributes['class']Noundefined-
menu-panel-styleInline styles to apply to the dropdown menu panel Useful for custom styling. You may use !important to override default stylesHTMLAttributes['style']Noundefined-
blockMakes the dropdown button expand to full width of its containerbooleanNofalse-
dropdown-iconIcon to use instead of the default chevron for the dropdown indicator Can be either an icon name string or a Vue component
Example: 'arrow-down'
string | IconComponentNoundefined-
dropdown-icon-animationControls whether the dropdown icon rotates when the dropdown is openedbooleanNotrue-
sizeSize of the dropdown buttonMazSizeNomdmini, xs, sm, md, lg, xl
transitionTransition to use when the dropdown is opened or closedMazPopoverProps['transition']Noscale-popscale-pop' | 'scale-fade' | string

Events

Event namePropertiesDescription
menuitem-clickedevent Event - The native click event from the menu item interactionEmitted when a menu item is clicked
update:model-valuevalue boolean - The new open state (true when opened, false when closed)Emitted when the dropdown open state changes

Slots

NameDescriptionBindings
screen-reader-descriptiondescription for screen readers (hidden from visual display)
triggertrigger element for the dropdownis-open boolean - Current state of the dropdown (true when open, false when closed)
toggle () =&gt; void - Function to toggle the dropdown
close () =&gt; void - Function to close the dropdown
open () =&gt; void - Function to open the dropdown
defaultText content of the trigger element
dropdown-iconDropdown indicator iconis-open boolean - Current state of the dropdown (true when open, false when closed)


dropdownDropdown menu panel contentitems MazDropdownMenuItem[] - Array of menu items passed via the items prop
open () =&gt; void - Function to open the dropdown
close () =&gt; void - Function to close the dropdown
is-open boolean - Current state of the dropdown (true when open, false when closed)
toggle () =&gt; void - Function to toggle the dropdown
menuitemMenu item componentitem MenuItem - Individual menu item object with properties like label, href, onClick, etc.
open () =&gt; void - Function to open the dropdown
close () =&gt; void - Function to close the dropdown
is-open boolean - Current state of the dropdown (true when open, false when closed)
toggle () =&gt; void - Function to toggle the dropdown
menuitem-labelLabel content for menu itemitem MenuItem - Individual menu item object containing label and other properties
open () =&gt; void - Function to open the dropdown
close () =&gt; void - Function to close the dropdown
is-open boolean - Current state of the dropdown (true when open, false when closed)
toggle () =&gt; void - Function to toggle the dropdown