import{o as a,a as t,y as n}from"./vue-libs.b44bc779.js";const l={class:"van-doc-markdown-body"},e=n(`

DropdownMenu

Intro

The menu list that pops down downwards.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { DropdownMenu, DropdownItem } from 'vant';

const app = createApp();
app.use(DropdownMenu);
app.use(DropdownItem);

Usage

Basic Usage

<van-dropdown-menu>
  <van-dropdown-item v-model="value1" :options="option1" />
  <van-dropdown-item v-model="value2" :options="option2" />
</van-dropdown-menu>
import { ref } from 'vue';

export default {
  setup() {
    const value1 = ref(0);
    const value2 = ref('a');
    const option1 = [
      { text: 'Option1', value: 0 },
      { text: 'Option2', value: 1 },
      { text: 'Option3', value: 2 },
    ];
    const option2 = [
      { text: 'Option A', value: 'a' },
      { text: 'Option B', value: 'b' },
      { text: 'Option C', value: 'c' },
    ];

    return {
      value1,
      value2,
      option1,
      option2,
    };
  },
};

Custom Content

<van-dropdown-menu>
  <van-dropdown-item v-model="value" :options="options" />
  <van-dropdown-item title="Title" ref="item">
    <van-cell center title="Title">
      <template #right-icon>
        <van-switch v-model="switch1" size="24" active-color="#ee0a24" />
      </template>
    </van-cell>
    <van-cell center title="Title">
      <template #right-icon>
        <van-switch v-model="switch2" size="24" active-color="#ee0a24" />
      </template>
    </van-cell>
    <div style="padding: 5px 16px;">
      <van-button type="danger" block round @click="onConfirm">
        Confirm
      </van-button>
    </div>
  </van-dropdown-item>
</van-dropdown-menu>
import { ref } from 'vue';

export default {
  setup() {
    const item = ref(null);
    const value = ref(0);
    const switch1 = ref(false);
    const switch2 = ref(false);
    const options = [
      { text: 'Option1', value: 0 },
      { text: 'Option2', value: 1 },
      { text: 'Option3', value: 2 },
    ];
    const onConfirm = () => {
      item.value.toggle();
    };

    return {
      item,
      value,
      switch1,
      switch2,
      options,
      onConfirm,
    };
  },
};

Custom Active Color

Use active-color prop to custom active color of the title and options.

<van-dropdown-menu active-color="#1989fa">
  <van-dropdown-item v-model="value1" :options="option1" />
  <van-dropdown-item v-model="value2" :options="option2" />
</van-dropdown-menu>

Expand Direction

<van-dropdown-menu direction="up">
  <van-dropdown-item v-model="value1" :options="option1" />
  <van-dropdown-item v-model="value2" :options="option2" />
</van-dropdown-menu>

Disabled

<van-dropdown-menu>
  <van-dropdown-item v-model="value1" disabled :options="option1" />
  <van-dropdown-item v-model="value2" disabled :options="option2" />
</van-dropdown-menu>

API

AttributeDescriptionTypeDefault
active-colorActive color of title and optionstring#ee0a24
directionExpand direction, can be set to upstringdown
z-indexz-index of menu itemnumber | string10
durationTransition duration, unit secondnumber | string0.2
overlayWhether to show overlaybooleantrue
close-on-click-overlayWhether to close when overlay is clickedbooleantrue
close-on-click-outsideWhether to close when outside is clickedbooleantrue
AttributeDescriptionTypeDefault
v-modelValue of current optionnumber | string-
titleItem titlestringText of selected option
optionsOptionsOption[][]
disabledWhether to disable dropdown itembooleanfalse
lazy-renderWhether to lazy render util openedbooleantrue
title-classTitle classstring | Array | object-
teleportSpecifies a target element where DropdownItem will be mountedstring | Element-
EventDescriptionArguments
changeEmitted select option and value changedvalue: number | string
openEmitted when opening menu-
closeEmitted when closing menu-
openedEmitted when menu is opened-
closedEmitted when menu is closed-
NameDescription
defaultContent
titleCustom title

Use ref to get DropdownItem instance and call instance methods.

NameDescriptionAttributeReturn value
toggleToggle displayshow?: boolean-

Types

The component exports the following type definitions:

import type {
  DropdownMenuProps,
  DropdownItemProps,
  DropdownItemOption,
  DropdownItemInstance,
  DropdownMenuDirection,
} from 'vant';

DropdownItemInstance is the type of component instance:

import { ref } from 'vue';
import type { DropdownItemInstance } from 'vant';

const dropdownItemRef = ref<DropdownItemInstance>();

dropdownItemRef.value?.toggle();

Data Structure of Option

KeyDescriptionType
textTextstring
valueValuenumber | string
iconLeft iconstring

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-dropdown-menu-height48px-
--van-dropdown-menu-background-colorvar(--van-background-color-light)-
--van-dropdown-menu-box-shadow0 2px 12px fade(var(--van-gray-7), 12)-
--van-dropdown-menu-title-font-size15px-
--van-dropdown-menu-title-text-colorvar(--van-text-color)-
--van-dropdown-menu-title-active-text-colorvar(--van-danger-color)-
--van-dropdown-menu-title-disabled-text-colorvar(--van-text-color-2)-
--van-dropdown-menu-title-padding0 var(--van-padding-xs)-
--van-dropdown-menu-title-line-heightvar(--van-line-height-lg)-
--van-dropdown-menu-option-active-colorvar(--van-danger-color)-
--van-dropdown-menu-content-max-height80%-
--van-dropdown-item-z-index10-
`,19),p=[e],i={__name:"README",setup(d,{expose:s}){return s({frontmatter:{}}),(r,c)=>(a(),t("div",l,p))}};export{i as default};