Skip to content

FxDropdown 下拉菜单

可展开的菜单,用于展示链接或操作列表。不依赖任何 UI 框架,基于 FxTooltip 浮层 + FxScrollbar 滚动 + FxBtn split-button。

基础用法

悬停在下拉菜单上展开。

触发元素由默认 slot 渲染,下拉部分由 dropdown 具名插槽渲染。默认 hover 触发。

位置(placement)

支持 6 个位置。

通过 placement 属性设置下拉出现位置:top / top-start / top-end / bottom / bottom-start / bottom-end

触发元素

用按钮触发下拉列表。

split-button 将触发元素拆成按钮组:左侧普通按钮、右侧触发箭头。给某项加 divided 显示分隔线。

触发方式

点击或悬停触发。

trigger 属性,默认 hover,可选 click / contextmenu

菜单隐藏行为(hide-on-click)

默认点击菜单项后关闭,设 hide-on-clickfalse 可保持打开。

命令事件(command)

点击每个菜单项触发事件,参数由各项的 command 指定。

方法(methods)

手动用 open / close 打开或关闭菜单。

尺寸(size)

除默认尺寸外,Dropdown 提供 large / default / small 三种额外尺寸。

虚拟触发(virtual-triggering)

需要把下拉渲染到其他触发元素上时,可分离触发器与内容。

virtual-triggering + virtual-ref 把下拉挂到指定元素上,此时默认 slot 不再渲染。

FxDropdown API

Attributes

属性说明类型默认值
type菜单按钮类型(split-button 为 true 时生效)'' | 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger' | 'text'''
size菜单尺寸(也作用于 split-button)'' | 'large' | 'default' | 'small'''
button-propssplit-button 按钮 propsobject
max-height菜单最大高度string / number''
split-button是否按钮组形式booleanfalse
disabled是否禁用booleanfalse
placement菜单位置'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end'bottom
effecttooltip 主题'dark' | 'light'light
trigger触发方式'click' | 'hover' | 'contextmenu' | Array<'click' | 'hover' | 'contextmenu'>hover
trigger-keys触发按键string[]['Enter','Space','ArrowDown','NumpadEnter']
virtual-triggering是否虚拟触发boolean
virtual-ref虚拟触发参考元素HTMLElement
hide-on-click点击菜单项后是否隐藏booleantrue
show-arrow是否显示箭头booleantrue
show-timeout显示延迟(trigger 为 hover)number150
hide-timeout隐藏延迟(trigger 为 hover)number150
role菜单 ARIA role'menu' | 'navigation' | …menu
tabindextabindexnumber / string0
popper-class菜单自定义类名string / object
popper-style菜单自定义样式string / object
popper-options浮层配置(仅读取 placement/strategy)object{}
teleported是否 teleport 到 bodybooleantrue
append-toteleport 目标string / HTMLElement
persistent失活时是否销毁booleantrue

Slots

插槽名说明子标签
default触发器内容
dropdown菜单内容,通常是 <FxDropdownMenu>Dropdown-Menu

Events

事件名说明类型
clicksplit-button 主按钮点击(e: MouseEvent) => void
command菜单项点击时触发,参数为该项的 command(...args: any[]) => void
visible-change显隐变化(true=显示,false=隐藏)(val: boolean) => void

Exposes

方法说明类型
open打开下拉菜单() => void
close关闭下拉菜单() => void
handleOpen打开下拉菜单(open 别名)() => void
handleClose关闭下拉菜单(close 别名)() => void

FxDropdownMenu API

Slots

插槽名说明子标签
default菜单内容Dropdown-Item

FxDropdownItem API

Attributes

属性说明类型默认值
command派发给 command 回调的值string / number /
disabled是否禁用booleanfalse
divided是否显示分隔线booleanfalse
textValue文本值(无障碍 aria-label 用)string
icon自定义图标。字符串为 IconString 类型(即 FxIcon 图标名,如 ep:editant-design:homesvg:xxx),亦可传组件string / Component

Slots

插槽名说明
default自定义菜单项内容
icon自定义图标(覆盖 icon prop)