Menu 展示一组即时命令或简单选项。复杂表单使用 Popover,视觉预设使用 PresetGallery,需要确认的任务使用 Dialog。
数据配置
直接使用 <QuireMenu :items="items" @select="onSelect">,只需为 trigger 插槽提供打开按钮。QuireKitMenuEntry[] 支持普通动作、group、submenu、separator 和 radio-group,子项放入 children。icon 引用注册表,shortcut、disabled、reason 与 tone 描述条目。
checked 声明勾选项;radio-group 的 selectedValue 声明单选值。两者都在右侧显示对号,左侧 icon 独立表达功能,不能用勾选项模拟互斥单选。select(value) 每次返回一个被执行的叶子值,由调用方更新数据;勾选和单选默认保持菜单打开,closeOnSelect 可按项覆盖。分隔项使用稳定 value 和空 label。显式默认插槽优先于 items,适合自定义复杂内容。
基础用法
使用 Item 执行动作,Group 与 Separator 组织条目。shortcut 使用共享 Kbd 展示快捷键,实际快捷键由调用方注册。组合键推荐传入 :shortcut="['Shift', 'Enter']",保留字符串形式兼容既有调用。
Checkbox 选项
CheckboxItem 用于可独立开关的偏好,默认选择后保持菜单打开,方便连续调整。
Radio 选项
RadioGroup 管理一组互斥选项,RadioItem 显示当前选择。
禁用与危险动作
disabled 条目保留标签和说明,但不参与键盘导航或执行。tone="danger" 突出危险动作;需要确认时,在选择后打开 Dialog。
子菜单
使用 QuireMenuSubmenu 组织次级操作。用户可通过指针或方向键进入,并使用 ArrowLeft 返回父菜单。
手工组合条目时,在对应子菜单上监听 @select 可取得本层执行的条目值,包含再次选择当前单选项。
需要每次执行设置时使用该事件;只关心单选值变化时,监听单选组的 v-model 即可。
内容宽度
默认宽度为 200px。width 指定固定宽度,width="auto" 按内容收缩;minWidth 与 maxWidth 可以单独使用或组合成范围。子菜单使用相同属性。
达到宽度上限时,标签显示省略号,选中标记、快捷键和子菜单图标保持可见。所有传送到页面的 Menu 都受当前视口宽高约束,空间不足时自动翻转或沿边缘滑动;长列表独立滚动,系统滚动条不改变条目列对齐。 子菜单与根菜单使用相同的视口定位,纵向对齐入口行,横向与父菜单外边缘保持 6px 间隔, 不因传送容器的位置滚动整页。空间不足时翻转到另一侧或沿纵向调整;宽度受该侧可用空间约束, 不会为贴合视口而覆盖父菜单。子菜单的浮层层级始终高于父菜单,不依赖传送节点的挂载顺序。 总高度默认不超过动态视口的 60%,并取锚点可用高度中的较小值;短菜单仍按内容收缩。 该预算与 Popover 共用,见浮层尺寸边界。
受控状态与位置
v-model:open 控制打开状态,并同步选择、Escape 和外部点击。placement 指定首选位置,组件根据可用空间调整最终位置。
宿主有独立浮层容器时可设置 portalTarget(元素或选择器);嵌套子菜单自动继承同一目标,
不同菜单根的挂载目标互不影响。默认仍挂载到 body。
菜单内容可以组合 QuireScrollArea:键盘导航和前缀搜索改变高亮条目时,公共 Menu 会让内层
滚动区显示该条目,不滚动文档。该同步只观察已挂载菜单的活动条目,关闭时释放。
宿主已有定位与可视边界管理时,使用 :positioned="false" :portalled="false",通过 style 为菜单内容指定坐标和最大尺寸。Menu 保留主题、条目、键盘导航和关闭行为;坐标改变不播放位移动画。
条目与分组
分组标题使用较小字号、辅助色和紧凑留白,组内操作向内缩进,便于区分标题与命令。 标题不响应操作,也不进入键盘导航;省略标题的分组不增加缩进。
QuireMenuItem @select处理当前条目的执行;根组件的@select(value)可统一接收所选值。指针与键盘操作触发相同事件,禁用项不会触发。- 普通 Item 默认执行后关闭;CheckboxItem 默认保持打开。
- 使用
leading插槽添加图标。无图标条目或分组标题需要与图标列对齐时,设置inset。 - 分组标题也有
leading与trailing插槽:前者放这一组的标记(如来源图标),后者放一小段状态(如“已登录”)。标题文字过长时先省略标题,状态完整显示;两个插槽都只是装饰,键盘导航与可访问名称仍只用label。 - Item、CheckboxItem 与 RadioItem 的
description在标签下方显示一行简短说明,条目高度随之增加;说明只补充标签未表达的结果,不重复解释标签左侧图标与右侧对号对齐标签所在的第一行,不在两行之间居中。 - Checkbox 与 Radio 条目始终在右侧为对号保留位置,快捷键位于对号之前;
leading插槽和inset管理独立的左侧图标列。单选/多选语义及键盘行为不因对号外观一致而改变。 - 单一设置菜单可使用空的 radio-group
label隐藏重复标题,同时为 Menu 提供可访问名称;多个设置组使用可见标题区分。 - 菜单和子菜单可以放在 Dialog 或 Drawer 中,关闭子菜单后返回父菜单的入口行;父菜单含内嵌工具栏或字段时,仍可直接用 ArrowRight 再次进入子菜单。
键盘操作
菜单默认将初始焦点交给内嵌的搜索框等可聚焦控件。设置 initial-focus="menu" 可让焦点先
落在菜单本身,适用于包含图标工具栏、希望打开时不触发按钮提示的菜单;Tab 仍可进入内嵌控件。
| 按键 | 行为 |
|---|---|
| ArrowUp / ArrowDown | 在可用条目之间移动。 |
| Home / End | 到达首个或末个可用条目。 |
| Enter / Space | 执行动作或切换选项。 |
| ArrowRight / ArrowLeft | 进入或离开子菜单。 |
| Escape | 关闭菜单并恢复入口焦点。 |
| 字符键 | 按条目标签查找。 |
打开对话框
菜单动作可以打开重命名或确认对话框。将 Dialog 放在菜单外部,避免菜单关闭时一起卸载;通过 finalFocusEl 将最终焦点返回菜单按钮。
右键操作使用 ContextMenu。
QuireMenuSubmenu 的 triggerClass 与 contentClass 分别附加到子菜单入口和内容根节点,适合组合多行操作或调整触控密度。需要自动切换到底部操作面板时,使用 ActionMenu。
坐标菜单与多实例
普通 HTML 属性应用到菜单内容,触发器属性放在 trigger 插槽的按钮上。多个独立 Vue 应用应设置不同的 app.config.idPrefix,避免重复 ID。
anchorPoint 接收视口 CSS 像素坐标 { x, y },适合 Canvas/SVG 等已经完成命中的交互打开菜单。
坐标型 Menu 使用 fixed 视口定位,每个新坐标建立新的定位生命周期,不能先用 (0, 0) 占位再打开。
宿主负责转换业务坐标并在关闭后安排焦点返回。常规 DOM 右键操作直接使用 ContextMenu。
声明式菜单与内联列表
QuireMenuItems 使用 QuireKitMenuEntry[] 描述条目、分组和子菜单,通过 select(value) 处理动作。leading 插槽添加静态图标或色块,contentProps 配置子菜单内容。
QuireCommandList 用于已存在浮层中的常驻命令列表,支持上下方向键和 Home / End;不要再套一层 Menu。条目的 group 为相邻同组命令添加一次轻量标题,标题不进入键盘导航;description 在标签旁显示辅助说明,并通过 aria-describedby 关联。leading 可放图标,列表激活时仍只发出稳定的 key。组合示例见 Chat Composer。
搜索输入或编辑器需要保留焦点时,把真实输入元素传给 focusOwner,并将原生 keydown
转发到模板引用的 handleKeydown(event)。列表负责高亮、滚动和 aria-activedescendant,
不会聚焦条目;返回 true 表示已处理。输入法组合键、带修饰键的输入继续交给原控件。
筛选由宿主负责,取消由外层浮层负责;卸载后恢复输入原有的 ARIA 属性。
API
QuireMenu Props
Slots 内容位置
triggerSingle interactive element that opens the menu.
anydefaultMenu groups, rows, separators, and nested menus.
any
Events 组件事件
update:open更新
open,可通过对应 v-model 绑定。[value: boolean | undefined]select[value: string]highlightChange[value: string | null]
QuireMenuItem Props
Slots 内容位置
defaultVisible item label.
anyleadingOptional leading icon.
anytrailingOptional trailing content that replaces the shortcut prop.
any
Events 组件事件
select[]
QuireMenuGroup Props
Slots 内容位置
defaultRows contained by this visual and semantic group.
anyleadingDecorative mark before the label, such as the icon of the source the rows belong to.
anytrailingShort status after the label, such as a signed-in state; it is not read as part of the label.
any
Events 组件事件
无自定义事件。
QuireMenuCheckboxItem Props
Slots 内容位置
defaultVisible option label.
anyleadingOptional functional icon, separate from the trailing checked state.
anytrailingOptional trailing content that replaces the shortcut prop.
any
Events 组件事件
update:checked更新
checked,可通过对应 v-model 绑定。[value: boolean]
QuireMenuRadioGroup Props
Slots 内容位置
defaultRadio items belonging to this mutually exclusive option set.
any
Events 组件事件
update:modelValue更新
modelValue,可通过对应 v-model 绑定。[value: string]
QuireMenuRadioItem Props
Slots 内容位置
defaultVisible option label.
anyleadingOptional functional icon, separate from the trailing checked state.
anytrailingOptional trailing content that replaces the shortcut prop.
any
Events 组件事件
无自定义事件。
QuireMenuSubmenu Props
Slots 内容位置
triggerVisible label of the parent-menu trigger row.
anyleadingOptional leading icon for the trigger row.
anydefaultChild menu rows.
any
Events 组件事件
update:open更新
open,可通过对应 v-model 绑定。[value: boolean | undefined]select[value: string]
QuireMenuItems Props
Slots 内容位置
leadingOptional product-owned leading illustration, recursively forwarded to leaves.
{ item: { /** Stable identity emitted for executable rows. */ value: string; /** Localized visible label. */ label: string; /** Group, submenu or ordinary action. */ kind?: undefined | "group" | "item" | "submenu" | "separator" | "radio-group"; /** Ordered rows belonging to a group or submenu. */ children?: undefined | readonly (QuireKitMenuEntry)[]; /** Whether activation is unavailable. */ disabled?: boolean | undefined; /** Optional explanation of an unavailable action. */ reason?: undefined | string; /** Shortcut rendered with Kbd; pass explicit keys for combined shortcuts, or a legacy display string. */ shortcut?: undefined | string | readonly (string)[]; /** Icon name resolved by the current QuireIconProvider. */ icon?: string | undefined; /** Current value of a radio group; its children describe the options. */ selectedValue?: string | undefined; /** Whether activating a leaf closes the menu; checkboxes and radio items default to false. */ closeOnSelect?: boolean | undefined; /** Checked state for a toggle row; omission is an ordinary action. */ checked?: boolean | undefined; /** Visual action emphasis. */ tone?: undefined | "neutral" | "danger"; }; }
Events 组件事件
select[value: string]
QuireCommandList Props
Slots 内容位置
leadingOptional leading icon or state mark.
{ /** Current stable command declaration. */ item: { /** Stable feature-owned identity emitted on activation. */ key: string; /** Localized visible and accessible row label. */ label: string; /** 相邻的相同分组只显示一次标题;不加入键盘停靠点。 */ group?: undefined | string; /** 命令的简短辅助说明,不进入主标签或键盘查找。 */ description?: string | undefined; /** Whether the command is currently unavailable. */ disabled?: boolean | undefined; /** Optional radio state; omission renders an ordinary menu item. */ checked?: boolean | undefined; /** Whether a semantic divider precedes this command. */ separatorBefore?: boolean | undefined; }; /** Zero-based position in the ordered menu. */ index: number; }trailingOptional trailing shortcut or disclosure mark.
{ /** Current stable command declaration. */ item: { /** Stable feature-owned identity emitted on activation. */ key: string; /** Localized visible and accessible row label. */ label: string; /** 相邻的相同分组只显示一次标题;不加入键盘停靠点。 */ group?: undefined | string; /** 命令的简短辅助说明,不进入主标签或键盘查找。 */ description?: string | undefined; /** Whether the command is currently unavailable. */ disabled?: boolean | undefined; /** Optional radio state; omission renders an ordinary menu item. */ checked?: boolean | undefined; /** Whether a semantic divider precedes this command. */ separatorBefore?: boolean | undefined; }; /** Zero-based position in the ordered menu. */ index: number; }
Events 组件事件
select[key: string]
公开实例成员
handleKeydown(event: KeyboardEvent) => boolean
QuireMenuSeparator Props
Slots 内容位置
无公开插槽。
Events 组件事件
无自定义事件。