Skip to content

DropdownMenu - Vant 4

DropdownMenu

📋 Create elegant dropdown menus that make option selection a breeze!

🎯 Intro

Meet the DropdownMenu component - your ultimate solution for space-efficient option selection! 🚀 Perfect for filters, sorting options, or any scenario where you need to present multiple choices without cluttering your interface. With smooth animations, customizable styling, and intuitive interactions, your users will love how easy it is to navigate through options! ✨

📦 Install

Get your DropdownMenu components ready for action! Register both DropdownMenu and DropdownItem globally via app.use and start creating intuitive selection interfaces! 🎯 Check out our Component Registration guide for more installation options.

js
import { createApp } from'vue'; import { DropdownMenu, DropdownItem } from'vant'; const app = createApp(); app.use(DropdownMenu); app.use(DropdownItem);

🎨 Usage

📋 Basic Usage

The foundation of great user experience! Create simple, clean dropdown menus that let users select from predefined options effortlessly. Perfect for categories, filters, or any selection scenario! 🌟

html
js
import { ref } from'vue'; exportdefault { 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

Go beyond simple text options! Create rich, interactive dropdown content with custom components, switches, buttons, or any Vue elements. Perfect for complex filters or advanced selection interfaces! 🛠️

html
js
import { ref } from'vue'; exportdefault { setup() { const menuRef = ref(null); const itemRef = 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 }, ]; constonConfirm = () => { item.value.toggle(); // or// menuRef.value.close(); }; return { menuRef, itemRef, value, switch1, switch2, options, onConfirm, }; }, };

🌈 Custom Active Color

Make it match your brand! Use the active-color prop to customize the color of active titles and selected options, ensuring perfect integration with your design system. 🎯

html

👆 Swipe Items

Handle lots of options gracefully! When you have many dropdown items, enable horizontal swiping by setting the swipe-threshold prop. Your users can easily navigate through all available options! 📱

html

⬆️ Expand Direction

Control where your dropdown appears! Set the expand direction to up when you need the menu to open upward - perfect for bottom navigation or when space is limited below! 🔄

html

🚫 Disabled

Sometimes options need to be temporarily unavailable. Easily disable dropdown items to provide visual feedback while maintaining a clean interface structure! 💤

html

API

AttributeDescriptionTypeDefault
active-colorActive color of title and optionstring#1989fa

| direction | Expand direction, can be set to up | string | down | | z-index | z-index of menu item | number | string | 10 | | duration | Transition duration, unit second | number | string | 0.2 | | overlay | Whether to show overlay | boolean | true | | close-on-click-overlay | Whether to close when overlay is clicked | boolean | true | | close-on-click-outside | Whether to close when outside is clicked | boolean | true | | swipe-threshold | Horizontal scrolling is allowed when the number of items exceeds the threshold and the total width exceeds the width of the menu. | number | string | - | | auto-locate | When the ancestor element is set with a transform, the position of the dropdown menu will be automatically adjusted. | boolean | false |

AttributeDescriptionTypeDefault
v-modelValue of current option*numberstring*
titleItem titlestringText of selected option
optionsOptionsOption[][]
disabledWhether to disable dropdown itembooleanfalse
lazy-renderWhether to lazy render util openedbooleantrue
title-classTitle class*stringArray
teleportSpecifies a target element where DropdownItem will be mounted*stringElement*
EventDescriptionArguments
changeEmitted select option and value changed*value: number
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 DropdownMenu instance and call instance methods.

NameDescriptionAttributeReturn value
closeClose all dropdown items--

Use ref to get DropdownItem instance and call instance methods.

NameDescriptionAttributeReturn value
toggleToggle displayshow?: boolean-

Types

The component exports the following type definitions:

ts
importtype { DropdownMenuProps, DropdownItemProps, DropdownItemOption, DropdownItemInstance, DropdownMenuInstance, DropdownMenuDirection, } from'vant';

DropdownMenuInstance and DropdownItemInstance are the types of component instances:

ts
import { ref } from'vue'; importtype { DropdownMenuInstance, DropdownItemInstance } from'vant'; const dropdownMenuRef = ref<DropdownMenuInstance>(); const dropdownItemRef = ref<DropdownItemInstance>(); dropdownMenuRef.value?.close(); dropdownItemRef.value?.toggle();

Data Structure of Option

KeyDescriptionType
textTextstring
valueValue*number
disabledWhether to disable optionboolean
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-backgroundvar(--van-background-2)-
--van-dropdown-menu-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-primary-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-primary-color)-
--van-dropdown-menu-option-disabled-colorvar(--van-text-color-3)-
--van-dropdown-menu-content-max-height80%-
--van-dropdown-item-z-index10-

## 🔗 Related Docs

- [Picker](./picker) - Column-based option selection
- [ActionSheet](./action-sheet) - Bottom action selection
- [Popup](./popup) - Modal overlay components
- [NavBar](./nav-bar) - Navigation bar with dropdown support
- [Tab](./tab) - Tabbed navigation
- [Field](./field) - Form input components
- [Button](./button) - Interactive button components
- [ConfigProvider](./config-provider) - Global configuration
- [Advanced Usage](./advanced-usage) - Advanced component techniques

Enterprise-level mobile solution based on Vant