# DropMenu Drop-down Menu
A menu list that drops down or up.
## Basic Usage
Basic usage requires binding a `v-model` value and the `options` property.
The `options` property is a one-dimensional object array, where each array item's data structure includes: label (option text), value (option value), tip (option description).
Since `uni-app` components cannot listen for clicks outside themselves, to automatically close the `dropmenu` when clicking elsewhere on the page, it is recommended to use the component library's `useQueue` hook (which will close all dropmenu, popover, toast, swipeAction, fab), and listen for click event bubbling on the page's root element.
:::warning
If there is a scenario where the user manually clicks somewhere outside the `dropmenu` like a button to open the `dropmenu`, then you need to add @click to the clicked element (in this case the button) to prevent event bubbling to the root element, avoiding triggering `closeOutside` which would close the `dropmenu` that should be manually opened.
:::
```html
```
```typescript
import { useQueue } from '@/uni_modules/wot-design-uni'
const { closeOutside } = useQueue()
const value1 = ref(0)
const value2 = ref(0)
const option1 = ref[]>([
{ label: 'All Products', value: 0 },
{ label: 'New Products', value: 1 },
{ label: 'Promotional Products', value: 2 }
])
const option2 = ref[]>([
{ label: 'Comprehensive', value: 0 },
{ label: 'Sales', value: 1 },
{ label: 'Listing Time', value: 2 }
])
function handleChange1({ value }) {
console.log(value)
}
function handleChange2({ value }) {
console.log(value)
}
```
## Custom Menu Content
You can customize the content of `DropMenuItem` through the `default` slot. In this case, you need to use the instance's `close` method to manually control the menu's closure.
You can set the menu title through `title`.
> Don't pass in options and value at this time
```html
Primary Button
```
```typescript
const dropMenu = ref()
const slider = ref() // slider 1.2.25 supported
const value = ref(0)
const sliderValue = ref(30)
const option = ref[]>([
{ label: 'All Products', value: 0 },
{ label: 'New Products', value: 1 },
{ label: 'Promotional Products', value: 2 }
])
function handleChange({ value }) {
console.log(value)
}
function confirm() {
dropMenu.value.close()
}
function handleOpened() {
slider.value?.initSlider()
}
```
## Custom Menu Options
Create custom filter display using flex layout.
```html
```
## Custom Menu Icon1.3.7
You can set the menu's right icon through `icon`, equivalent to the `name` property of ``. Set the icon size through `icon-size`, equivalent to the `size` property of ``.
```html
```
## Asynchronous Open/Close1.3.7
Set the `before-toggle` function to execute specific logic before the dropdown menu opens or closes, achieving the purpose of state change validation and asynchronous open/close. `before-toggle` accepts { status: current operation type: true to open dropdown menu, false to close dropdown menu, resolve }, can validate the operation, and inform the component whether to confirm through the resolve function. resolve accepts a boolean value, resolve(true) means the option is approved, resolve(false) means the option is not approved, and when not approved, the close or expand operation will not be executed.
:::warning Note
The `before-toggle` function cannot prevent the expansion/closure operations of other `drop-menu` or other `drop-menu-item`, it is limited to the expansion/closure operation of the current `drop-menu-item`.
:::
```html
```
```typescript
import { useMessage } from '@/uni_modules/wot-design-uni'
import type { DropMenuItemBeforeToggle } from '@/uni_modules/wot-design-uni/components/wd-drop-menu-item/types'
const messageBox = useMessage()
const value = ref(0)
const option = ref[]>([
{ label: 'All Products', value: 0 },
{ label: 'New Products', value: 1 },
{ label: 'Promotional Products', value: 2 }
])
// Confirm whether to open/close the dropdown menu through dialog
const handleBeforeToggle: DropMenuItemBeforeToggle = ({ status, resolve }) => {
messageBox
.confirm({
title: `Asynchronous ${status ? 'Open' : 'Close'}`,
msg: `Are you sure you want to ${status ? 'open' : 'close'} the dropdown menu?`
})
.then(() => {
resolve(true)
})
.catch(() => {
resolve(false)
})
}
```
## Expand Upward
Set the `direction` property value to `up`, and the menu will expand upward
```html
```
## Disable Menu
```html
```
## DropMenu Attributes
| Parameter | Description | Type | Options | Default | Version |
|-----------|-------------|------|----------|---------|----------|
| direction | Menu expansion direction, can be `up` or `down` | string | up / down | down | - |
| modal | Whether to show overlay | boolean | - | true | - |
| close-on-click-modal | Whether to close when clicking overlay | boolean | - | true | - |
| duration | Menu expand/collapse animation time in ms | number | - | 200 | - |
## DropMenuItem Attributes
| Parameter | Description | Type | Options | Default | Version |
|-----------|-------------|------|----------|---------|----------|
| v-model | Selected value | string / number | - | - | - |
| disabled | Whether disabled | boolean | - | false | - |
| title | Title | string | - | - | - |
| options | Option array | array | - | - | - |
| icon | Right icon name | string | - | arrow-down | 1.3.7 |
| icon-size | Right icon size | string | - | 12px | 1.3.7 |
| before-toggle | Function executed before toggle | function(status: boolean, resolve: Function) | - | - | 1.3.7 |
| value-key | Key for value in options object | string | - | value | - |
| label-key | Key for display text in options object | string | - | label | - |
| tip-key | Key for option description in options object | string | - | tip | - |
| root-portal | Whether to detach from the page, used to solve various fixed positioning issues | boolean | - | false | 1.11.0 |
| icon-name | Selected icon name (available names in wd-icon component) | string | - | check | - |
## DropMenu Slot
| Name | Description | Version |
|------|-------------|----------|
| default | Menu content | - |
## DropMenuItem Slot
| Name | Description | Version |
|------|-------------|----------|
| default | Custom inner content of menu | - |
## DropMenu External Classes
| Class Name | Description | Version |
|------------|-------------|----------|
| custom-class | Root node style class of DropMenu | - |
## DropMenuItem External Classes
| Class Name | Description | Version |
|------------|-------------|----------|
| custom-class | Root node style class of DropMenuItem | - |
| custom-title | Style class for left text of DropMenuItem | - |
| custom-icon | Style class for right icon of DropMenuItem | - |
| custom-popup-class | Custom popup style class for dropdown menu | 1.5.0 |
| custom-popup-style | Custom popup style for dropdown menu | 1.5.0 |