Skip to content

DropMenu

Menu list that pops up downward or upward.

Component Type

Basic Usage

Basic usage requires binding v-model and options.

options is an object array, default structure is { label, value, tip }.

Because uni-app components cannot directly listen to clicks outside the component, to automatically close the dropdown menu when clicking other areas of the page, it is recommended to combine with useQueue to listen to click bubbling at the page root node and call closeOutside.

Tip

If there is a scenario where clicking an external button manually opens drop-menu, you need to add @click.stop to that button to avoid triggering closeOutside and immediately closing.

html
<view @click="closeOutside">
  <wd-drop-menu>
    <wd-drop-menu-item v-model="value1" :options="option1" @change="handleChange1" />
    <wd-drop-menu-item v-model="value2" :options="option2" @change="handleChange2" />
  </wd-drop-menu>
</view>
ts
import { ref } from 'vue'
import { useQueue } from '@/uni_modules/wot-ui'

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: 'Promotion Products', value: 2 }
])
const option2 = ref([
  { label: 'Comprehensive', value: 0 },
  { label: 'Sales', value: 1 },
  { label: 'Shelf Time', value: 2 }
])

const handleChange1 = ({ value }: { value: string | number }) => {
  console.log(value)
}
const handleChange2 = ({ value }: { value: string | number }) => {
  console.log(value)
}

Component State

Disabled Menu

Disable menu item through disabled.

html
<wd-drop-menu>
  <wd-drop-menu-item v-model="value1" disabled :options="option1" />
  <wd-drop-menu-item v-model="value2" :options="option2" />
</wd-drop-menu>

Component Variant

Expand Upward

Set direction to up to make menu expand upward.

html
<wd-drop-menu direction="up">
  <wd-drop-menu-item v-model="value1" :options="option1" />
  <wd-drop-menu-item v-model="value2" :options="option2" />
</wd-drop-menu>

Async Open/Close ^(1.3.7)

before-toggle triggers before menu opens/closes, receives { status }, supports returning boolean or Promise<boolean>.

Tip

before-toggle only acts on the current wd-drop-menu-item and cannot prevent the open/close behavior of other menu items.

html
<wd-dialog />
<wd-drop-menu>
  <wd-drop-menu-item v-model="value" :options="option" :before-toggle="handleBeforeToggle" />
</wd-drop-menu>
ts
import { ref } from 'vue'
import { useDialog } from '@/uni_modules/wot-ui'
import type { DropMenuItemBeforeToggle } from '@/uni_modules/wot-ui/components/wd-drop-menu-item/types'

const dialog = useDialog()
const value = ref(0)
const option = ref([
  { label: 'All Products', value: 0 },
  { label: 'New Products', value: 1, tip: 'This is supplementary info' },
  { label: 'Long Filter Option', value: 2 }
])

const handleBeforeToggle: DropMenuItemBeforeToggle = ({ status }) => {
  return new Promise<boolean>((resolve) => {
    dialog
      .confirm({
        title: status ? 'Async Open' : 'Async Close',
        msg: status ? 'Confirm to open dropdown menu?' : 'Confirm to close dropdown menu?'
      })
      .then(() => resolve(true))
      .catch(() => resolve(false))
  })
}

Component Style

Custom Menu Options

Can combine with layout components to achieve filter bar linkage display.

html
<view style="display: flex; background: #fff; text-align: center">
  <wd-drop-menu style="flex: 1; min-width: 0">
    <wd-drop-menu-item v-model="value1" :options="option1" />
  </wd-drop-menu>
  <view style="flex: 1">
    <wd-sort-button v-model="value2" title="Shelf Time" />
  </view>
</view>

Custom Menu Icon ^(1.3.7)

Can set right icon through icon, set icon size through icon-size.

html
<wd-drop-menu>
  <wd-drop-menu-item title="Map" icon="location" icon-size="14px" />
</wd-drop-menu>

Special Style

Custom Menu Content

Customize menu content through default slot; in custom content scenarios, usually manually close menu through instance method close.

html
<wd-drop-menu>
  <wd-drop-menu-item v-model="value" :options="option" />
  <wd-drop-menu-item ref="dropMenu" title="Filter" @opened="handleOpened">
    <view>
      <wd-slider v-model="sliderValue" ref="slider" />
      <wd-cell title="Title Text" value="Content" />
      <wd-cell title="Title Text" label="Description Info" value="Content" />
      <view style="padding: 0 10px 20px; box-sizing: border-box">
        <wd-button block size="large" @click="confirm">Primary Button</wd-button>
      </view>
    </view>
  </wd-drop-menu-item>
</wd-drop-menu>
ts
import { ref } from 'vue'
import type { SliderInstance } from '@/uni_modules/wot-ui/components/wd-slider/types'
import type { DropMenuItemInstance } from '@/uni_modules/wot-ui/components/wd-drop-menu-item/types'

const dropMenu = ref<DropMenuItemInstance>()
const slider = ref<SliderInstance>()
const sliderValue = ref(30)

const confirm = () => {
  dropMenu.value?.close()
}

const handleOpened = () => {
  slider.value?.initSlider()
}

DropMenu Attributes

ParameterDescriptionTypeDefault Value
z-indexPopup z-indexnumber12
directionMenu expand direction, optional values are up, downDropDirection'down'
modalWhether to show maskbooleantrue
close-on-click-modalWhether to close when clicking maskbooleantrue
durationMenu expand/collapse animation duration, unit msnumber200
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

DropMenuItem Attributes

ParameterDescriptionTypeDefault Value
v-model / modelValueCurrent selected valuestring | number-
disabledWhether to disable menubooleanfalse
optionsMenu option list, default structure is { label, value, tip }Array<Record<string, any>>[]
icon-nameSelected item icon namestring'check'
titleMenu title, after setting, title text is displayed with prioritystring-
iconMenu right iconstring'caret-down'
icon-sizeMenu icon sizestring | number-
before-toggle v1.3.7Menu toggle pre-interception function, receives { status }, returns boolean or Promise<boolean>DropMenuItemBeforeToggle-
value-keyOption value field namestring'value'
label-keyOption text field namestring'label'
tip-keyOption description field namestring'tip'
custom-popup-class v1.5.0Custom dropdown popup style classstring''
custom-popup-style v1.5.0Custom dropdown popup stylestring''
popup-height v1.13.0Popup height, when not set, default max height is 80%string''
root-portal v1.11.0Whether to detach from page document flow rendering, used to solve fixed invalidation problembooleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

DropMenuItem Events

Event NameDescriptionParameters
changeTriggered when selected value changes{ value, selectedItem }
openTriggered when menu starts to expand-
openedTriggered when menu expansion completes-
closeTriggered when menu starts to close-
closedTriggered when menu closing completes-

DropMenuItem Methods

Instance methods can be obtained through ref:

Method NameDescriptionParametersReturn Value
getShowPopGet whether current menu is expanded-boolean
openOpen menu-void
closeClose menu-void
toggleToggle menu switch-void

DropMenu Slots

NameDescriptionParameters
defaultMenu item container slot-

DropMenuItem Slots

NameDescriptionParameters
defaultCustom menu content-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-drop-menu-height$n-48菜单项高度
--wot-drop-menu-list-bg$filled-oppo菜单列表背景色
--wot-drop-menu-option-padding$padding-loose菜单项内边距
--wot-drop-menu-option-opacity-disabled$opacity-disabled菜单项禁用态透明度
--wot-drop-menu-option-padding-horizontal$padding-extra-loose菜单项水平内边距
--wot-drop-menu-arrow-size$n-16箭头图标大小
--wot-drop-menu-arrow-color$icon-auxiliary箭头图标颜色
--wot-drop-menu-arrow-color-active$primary-6箭头图标激活态颜色
--wot-drop-menu-arrow-spacing$spacing-super-tight箭头图标间距
--wot-drop-menu-text-color$text-main菜单文字颜色
--wot-drop-menu-text-font-size$typography-body-size-extra-large菜单文字字号
--wot-drop-menu-text-line-height$typography-body-line--height-size-extra-large菜单文字行高
--wot-drop-menu-text-font-weight-active$font-weight-medium菜单激活态字重
--wot-drop-menu-text-color-active$primary-6菜单激活态文字颜色

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.