fix: align Dropdown/Menu with the HeroUI baseline after fidelity audit

- menu-item.css keys disabled styling off the presence attribute Reka emits.
- Dropdown surfaces drive the ported enter/exit animations and use data-side
  for placement-specific motion.
- One role=menu per popup; items render their key as DOM id; submenu surfaces
  point aria-labelledby at the real trigger; MenuSection names its group from a
  nested Header.
- Custom (asChild) triggers stay keyboard focusable; library Button/Avatar keep
  their own layout instead of the custom-trigger rules.
- Items emit data-focused/data-hovered/data-pressed, expose the upstream render
  props to slots, and merge caller classes through tailwind-variants.
- Submenu triggers declare hasSubmenu explicitly and forward class/ARIA; the
  default submenu indicator uses the baseline chevron artwork.
- Demos restore Kbd slot="keyboard" (27x), IconSquarePlus, and remove the added
  comment, stray space and duplicated indicator SVGs.
- Document the page after the official structure and API tables, including
  renamed props, Vue extensions and remaining gaps.
This commit is contained in:
maoyingjie
2026-10-24 22:14:10 +08:00
parent 64aaf5e53f
commit 043a5418f3
27 changed files with 1124 additions and 254 deletions
@@ -1,22 +1,28 @@
<script lang="ts">
import {
Fragment,
computed,
defineComponent,
h,
inject,
provide,
ref,
useAttrs,
type PropType,
type Ref,
} from "vue";
import {
DropdownMenuContent as RekaDropdownMenuContent,
injectDropdownMenuRootContext,
} from "reka-ui";
import { dropdownVariants } from "@heroui-vue/styles";
import {
dropdownContextKey,
menuCloseKey,
submenuContentKey,
} from "../menu/context";
import { useOverlayAnimation } from "../overlay/animation";
import { menuSurfaceFromVNode } from "./dom";
/**
* Dropdown popover / menu content shell. Provides close for Menu items.
@@ -47,19 +53,28 @@ export default defineComponent({
rootCtx?.onOpenChange(false);
});
const contentElement = ref<HTMLElement | null>(null);
const isOpen = computed(() => rootCtx?.open.value ?? false);
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
isOpen as Ref<boolean>,
contentElement,
true,
);
return () => {
const cls = [dropdownCtx?.slots.value.popover(), attrs.class];
if (inSubmenu) {
// Reka SubContent already positions and dismisses this level;
// keep a lightweight shell so Menu styling still applies.
// the submenu trigger forwards attrs onto that element.
return h(Fragment, null, slots.default?.() as never);
}
return h(
RekaDropdownMenuContent as never,
{
...attrs,
class: cls,
class: dropdownCtx?.slots.value.popover({ class: attrs.class }),
"data-slot": "dropdown-popover",
"data-entering": entering.value || undefined,
"data-exiting": exiting.value || undefined,
side: props.side,
sideOffset: props.sideOffset,
align: props.align,
@@ -67,6 +82,17 @@ export default defineComponent({
avoidCollisions: props.avoidCollisions,
collisionPadding: props.collisionPadding,
loop: props.loop,
onAnimationend: onAnimationEnd,
onVnodeMounted: (vnode) => {
contentElement.value = menuSurfaceFromVNode(vnode);
},
onVnodeUpdated: (vnode) => {
const element = menuSurfaceFromVNode(vnode);
if (element) contentElement.value = element;
},
onVnodeUnmounted: () => {
contentElement.value = null;
},
},
slots,
);
@@ -2,12 +2,19 @@
import {
Fragment,
cloneVNode,
computed,
defineComponent,
h,
inject,
isVNode,
nextTick,
onMounted,
provide,
ref,
useAttrs,
useId,
watch,
type Ref,
type VNodeChild,
} from "vue";
import {
@@ -15,7 +22,11 @@ import {
DropdownMenuSubContent as RekaDropdownMenuSubContent,
DropdownMenuSubTrigger as RekaDropdownMenuSubTrigger,
} from "reka-ui";
import { dropdownVariants } from "@heroui-vue/styles";
import { dropdownContextKey, submenuContentKey } from "../menu/context";
import { useOverlayAnimation } from "../overlay/animation";
import { elementFromValue, menuSurfaceFromVNode } from "./dom";
import DropdownPopover from "./DropdownPopover.vue";
function flatten(nodes: VNodeChild[], out: VNodeChild[] = []): VNodeChild[] {
for (const n of nodes) {
@@ -25,10 +36,24 @@ function flatten(nodes: VNodeChild[], out: VNodeChild[] = []): VNodeChild[] {
return out;
}
function resolveElement(value: unknown): HTMLElement | null {
if (value instanceof Element) return value as HTMLElement;
const el = (value as { $el?: unknown } | null)?.$el;
return el instanceof Element ? (el as HTMLElement) : null;
/** Attributes a nested `<DropdownPopover>` may pass to the submenu surface. */
function inheritableAttrs(props: Record<string, unknown> | null) {
const out: Record<string, unknown> = {};
if (!props) return out;
for (const [key, value] of Object.entries(props)) {
if (key === "ref" || key === "key") continue;
if (
key === "class" ||
key === "style" ||
key === "id" ||
key === "role" ||
key.startsWith("data-") ||
key.startsWith("aria-") ||
/^on[A-Z]/.test(key)
)
out[key] = value;
}
return out;
}
/**
@@ -47,6 +72,41 @@ export default defineComponent({
const subOpen = ref(false);
const triggerRef = ref<unknown>(null);
const contentElement = ref<HTMLElement | null>(null);
const fallbackId = useId();
const { entering, exiting, onAnimationEnd } = useOverlayAnimation(
subOpen as Ref<boolean>,
contentElement,
true,
);
/**
* Reka labels the submenu surface with the id it generates for its own
* trigger, but our trigger item keeps the caller's `id` (the selection
* key), so that reference dangles. Point it at the real trigger element.
*/
function repairLabel() {
const content = contentElement.value;
const trigger = elementFromValue(triggerRef.value);
if (!content || !trigger) return;
const ids = (content.getAttribute("aria-labelledby") ?? "")
.split(/\s+/)
.filter(Boolean);
const resolves = ids.some(
(id) => content.ownerDocument.getElementById(id) !== null,
);
if (resolves) return;
if (!trigger.id) trigger.id = fallbackId;
content.setAttribute("aria-labelledby", trigger.id);
}
watch(
contentElement,
(element) => {
if (element) void nextTick(repairLabel);
},
{ flush: "post" },
);
onMounted(repairLabel as () => void);
function handleEscape(event: KeyboardEvent) {
if (event.key !== "Escape" || !subOpen.value) return;
@@ -59,13 +119,21 @@ export default defineComponent({
event.preventDefault();
event.stopPropagation();
subOpen.value = false;
resolveElement(triggerRef.value)?.focus();
elementFromValue(triggerRef.value)?.focus();
}
return () => {
const children = flatten(slots.default?.() ?? []);
const triggerVNode = children[0] ?? null;
const contentVNodes = children.slice(1);
const popoverVNode = contentVNodes.find(
(node) => isVNode(node) && node.type === DropdownPopover,
);
const popoverAttrs = inheritableAttrs(
isVNode(popoverVNode)
? (popoverVNode.props as Record<string, unknown> | null)
: null,
);
return h(
RekaDropdownMenuSub as never,
@@ -88,7 +156,11 @@ export default defineComponent({
default: () =>
triggerVNode
? cloneVNode(triggerVNode as never, {
...attrs,
ref: triggerRef as never,
// The item is a submenu trigger regardless of whether
// the caller renders an indicator.
hasSubmenu: true,
// Escape with focus on the trigger (pointer-opened
// submenu) must also close only this level.
onKeydown: handleEscape,
@@ -99,10 +171,29 @@ export default defineComponent({
h(
RekaDropdownMenuSubContent as never,
{
class: [dropdownCtx?.slots.value.popover()],
...popoverAttrs,
class: [dropdownCtx?.slots.value.popover(), popoverAttrs.class],
"data-slot": "dropdown-popover",
"data-submenu-content": "true",
"data-entering": entering.value || undefined,
"data-exiting": exiting.value || undefined,
onKeydown: handleEscape,
onAnimationend: onAnimationEnd,
onVnodeMounted: (vnode) => {
contentElement.value = menuSurfaceFromVNode(vnode);
void nextTick(repairLabel);
},
onVnodeUpdated: (vnode) => {
const element = menuSurfaceFromVNode(vnode);
if (!element) return;
contentElement.value = element;
// Reka re-applies its own trigger id on re-render, so the
// association is restored after every patch.
void nextTick(repairLabel);
},
onVnodeUnmounted: () => {
contentElement.value = null;
},
},
{
default: () =>
@@ -1,7 +1,17 @@
<script lang="ts">
import { defineComponent, h, inject, onBeforeUnmount, useAttrs } from "vue";
import {
defineComponent,
h,
inject,
nextTick,
onBeforeUnmount,
onMounted,
ref,
useAttrs,
} from "vue";
import { DropdownMenuTrigger as RekaDropdownMenuTrigger } from "reka-ui";
import { dropdownContextKey } from "../menu/context";
import { elementFromValue } from "./dom";
const LONG_PRESS_MOVE_PX = 10;
@@ -23,6 +33,7 @@ export default defineComponent({
setup(props, { slots }) {
const attrs = useAttrs();
const dropdownCtx = inject(dropdownContextKey, null);
const triggerRef = ref<unknown>(null);
const isLongPress = () =>
(dropdownCtx?.triggerMode.value ?? "press") === "longPress";
@@ -75,6 +86,33 @@ export default defineComponent({
dropdownCtx?.setOpen(!(dropdownCtx?.open.value ?? false));
}
/**
* Upstream's `Dropdown.Trigger` is a real `<button>`, so a custom trigger
* (e.g. an Avatar) stays keyboard operable. With `asChild` the element is
* whatever the caller supplied, so restore button semantics when it is not
* natively focusable.
*/
function ensureFocusable() {
const el = elementFromValue(triggerRef.value);
if (!el) return;
const tag = el.tagName;
const role = el.getAttribute("role");
if (
tag === "BUTTON" ||
(tag === "A" && el.hasAttribute("href")) ||
el.hasAttribute("tabindex") ||
role === "button" ||
role === "link" ||
role === "menuitem"
)
return;
if (!role) el.setAttribute("role", "button");
el.setAttribute("tabindex", "0");
}
onMounted(() => void nextTick(ensureFocusable));
onBeforeUnmount(clearPress);
const guardHandlers = {
onPointerdownCapture: onPointerdown,
onPointermoveCapture: onPointermove,
@@ -86,16 +124,17 @@ export default defineComponent({
onContextmenuCapture: clearPress,
};
onBeforeUnmount(clearPress);
return () => {
const trigger = h(
RekaDropdownMenuTrigger as never,
{
...attrs,
ref: triggerRef,
as: props.as,
asChild: props.asChild ?? true,
class: [dropdownCtx?.slots.value.trigger(), attrs.class],
class: dropdownCtx?.slots.value.trigger({
class: attrs.class as never,
}),
"data-slot": "dropdown-trigger",
},
slots,
@@ -0,0 +1,36 @@
import type { VNode } from "vue";
/** Resolve a component/ref handle to its DOM element. */
export function elementFromValue(value: unknown): HTMLElement | null {
if (value instanceof Element) return value as HTMLElement;
const el = (value as { $el?: unknown } | null)?.$el;
return el instanceof Element ? (el as HTMLElement) : null;
}
/**
* Resolve the element a vnode mounted to. Reka's content components expose the
* positioned element through `$el`; fragments (text nodes) resolve to null.
*/
export function elementFromVNode(
vnode: VNode | null | undefined,
): HTMLElement | null {
if (!vnode) return null;
const el = vnode.el;
if (el instanceof Element) return el as HTMLElement;
const proxyEl = (vnode.component?.proxy as { $el?: unknown } | null)?.$el;
return proxyEl instanceof Element ? (proxyEl as HTMLElement) : null;
}
/**
* Reka renders a positioning wrapper around the menu surface; the popover
* styles and animations live on the inner `[data-reka-menu-content]` node.
*/
export function menuSurfaceFromVNode(
vnode: VNode | null | undefined,
): HTMLElement | null {
const el = elementFromVNode(vnode);
if (!el) return null;
if (el.matches("[data-reka-menu-content]")) return el;
const inner = el.querySelector("[data-reka-menu-content]");
return inner instanceof Element ? (inner as HTMLElement) : el;
}
@@ -1,6 +1,15 @@
<script lang="ts">
import { defineComponent, h, useAttrs } from "vue";
import {
defineComponent,
h,
inject,
onUnmounted,
useAttrs,
useId,
watch,
} from "vue";
import { headerVariants } from "@heroui-vue/styles";
import { menuSectionLabelKey } from "../menu/context";
/**
* Collection / group section heading (RAC Header).
@@ -19,12 +28,33 @@ export default defineComponent({
},
setup(props, { slots }) {
const attrs = useAttrs();
// Inside a MenuSection the header names the group (upstream wires this
// through the collection); elsewhere it stays a plain heading element.
const section = inject(menuSectionLabelKey, null);
const autoId = useId();
let unregister: (() => void) | undefined;
const resolveId = () =>
(attrs.id as string | undefined) || (section ? autoId : undefined);
watch(
resolveId,
(id, prev) => {
if (!section || !id || id === prev) return;
unregister?.();
unregister = section.registerLabel(id);
},
{ immediate: true },
);
onUnmounted(() => {
unregister?.();
unregister = undefined;
});
function render() {
return h(
props.as,
{
...attrs,
id: resolveId(),
class: [headerVariants(), attrs.class],
"data-slot": "header",
},
@@ -20,6 +20,7 @@ import {
type NativeClickHandler =
((e: MouseEvent) => void) | ((e: MouseEvent) => void)[] | undefined;
type NativeHandler<Ev> = ((e: Ev) => void) | ((e: Ev) => void)[] | undefined;
export default defineComponent({
name: "MenuItem",
@@ -35,6 +36,12 @@ export default defineComponent({
},
/** Set false to keep the menu open after an action item. */
closeOnSelect: { type: Boolean, default: undefined },
/**
* Render this item as a submenu trigger. `DropdownSubmenuTrigger` sets it
* so the item no longer depends on a rendered indicator to know it has a
* submenu (upstream derives it from the collection structure).
*/
hasSubmenu: { type: Boolean, default: undefined },
},
emits: {
select: (_key: MenuKey) => true,
@@ -44,11 +51,17 @@ export default defineComponent({
const menuCtx = inject(menuContextKey, null);
const sectionCtx = inject(menuSectionContextKey, null);
const owner = sectionCtx?.selection ?? menuCtx?.selection;
const hasSubmenu = ref(false);
const indicatorSubmenu = ref(false);
const isFocused = ref(false);
const isHovered = ref(false);
const isPressed = ref(false);
const key = computed<MenuKey>(
() => props.id ?? (attrs.id as MenuKey | undefined) ?? "",
);
const hasSubmenu = computed(
() => props.hasSubmenu ?? indicatorSubmenu.value,
);
const isDisabled = computed(
() =>
props.isDisabled ||
@@ -72,9 +85,11 @@ export default defineComponent({
slots: slotsComputed,
isDisabled,
isSelected,
hasSubmenu: computed(() => hasSubmenu.value),
isFocused,
isPressed,
hasSubmenu,
setHasSubmenu(value: boolean) {
hasSubmenu.value = value;
indicatorSubmenu.value = value;
},
});
@@ -93,6 +108,16 @@ export default defineComponent({
menuCtx?.closeLevel();
}
/** Keep the caller's own handler(s) in front of the internal tracker. */
function withOwn<Ev extends Event>(
name: string,
own: (event: Ev) => void,
): NativeHandler<Ev> {
const user = (attrs as Record<string, NativeHandler<Ev>>)[name];
if (!user) return own;
return Array.isArray(user) ? [...user, own] : [user, own];
}
return () => {
// Hand the user handlers and our activation to Vue as one DOM `onClick`
// array so browser/Vue listener semantics stay intact: capture order,
@@ -105,6 +130,17 @@ export default defineComponent({
...(attrs as Record<string, unknown>),
};
delete rest.onClick;
for (const name of [
"onFocus",
"onBlur",
"onPointerDown",
"onPointerUp",
"onPointerCancel",
"onPointerEnter",
"onPointerLeave",
]) {
delete rest[name];
}
const clickChain: Array<(e: MouseEvent) => void> = (
Array.isArray(userOnClick)
@@ -118,12 +154,16 @@ export default defineComponent({
activate();
});
const roleAttr = (attrs.role as string | undefined) ?? role.value;
const domId = props.id ?? (attrs.id as MenuKey | undefined);
return h(
RekaMenuItem as never,
{
...rest,
class: [slotsComputed.value.item(), attrs.class],
role: (attrs.role as string | undefined) ?? role.value,
id: domId,
class: slotsComputed.value.item({ class: attrs.class as never }),
role: roleAttr,
"aria-checked":
selectionMode.value === "none"
? undefined
@@ -133,16 +173,52 @@ export default defineComponent({
"aria-disabled": isDisabled.value || undefined,
"data-slot": "menu-item",
"data-selected": isSelected.value || undefined,
// RAC's render-state hooks that the ported CSS and the official
// custom-styles demo rely on.
"data-focused": isFocused.value || undefined,
"data-hovered": isHovered.value || undefined,
"data-pressed": isPressed.value || undefined,
"data-has-submenu": hasSubmenu.value || undefined,
"data-selection-mode": selectionMode.value,
disabled: isDisabled.value,
textValue: props.textValue,
onClick: clickChain,
onFocus: withOwn<FocusEvent>("onFocus", () => {
isFocused.value = true;
}),
onBlur: withOwn<FocusEvent>("onBlur", () => {
isFocused.value = false;
isPressed.value = false;
}),
onPointerDown: withOwn<PointerEvent>("onPointerDown", () => {
isPressed.value = true;
}),
onPointerUp: withOwn<PointerEvent>("onPointerUp", () => {
isPressed.value = false;
}),
onPointerCancel: withOwn<PointerEvent>("onPointerCancel", () => {
isPressed.value = false;
}),
onPointerEnter: withOwn<PointerEvent>("onPointerEnter", () => {
isHovered.value = true;
}),
onPointerLeave: withOwn<PointerEvent>("onPointerLeave", () => {
isHovered.value = false;
isPressed.value = false;
}),
onSelect: (itemSelectEvent?: { preventDefault?: () => void }) => {
itemSelectEvent?.preventDefault?.();
},
},
slots,
{
default: () =>
slots.default?.({
isSelected: isSelected.value,
isFocused: isFocused.value,
isDisabled: isDisabled.value,
isPressed: isPressed.value,
}),
},
);
};
},
@@ -58,21 +58,29 @@ export default defineComponent({
const attrs = useAttrs();
const item = inject(menuItemContextKey, null);
return () => {
const isSelected = item?.isSelected.value ?? false;
const state = {
isSelected: item?.isSelected.value ?? false,
// Menu items have no indeterminate state; kept for the upstream
// render-prop contract.
isIndeterminate: false,
isFocused: item?.isFocused.value ?? false,
isDisabled: item?.isDisabled.value ?? false,
isPressed: item?.isPressed.value ?? false,
};
const content = slots.default
? slots.default({ isSelected })
? slots.default(state)
: props.type === "dot"
? DotIcon()
: CheckmarkIcon(isSelected);
: CheckmarkIcon(state.isSelected);
return h(
props.as,
{
...attrs,
"aria-hidden": "true",
class: [item?.slots.value.indicator(), attrs.class],
class: item?.slots.value.indicator({ class: attrs.class as never }),
"data-slot": "menu-item-indicator",
"data-type": props.type,
"data-visible": isSelected || undefined,
"data-visible": state.isSelected || undefined,
},
content,
);
@@ -9,6 +9,9 @@ import {
} from "vue";
import { menuItemContextKey } from "../menu/context";
/** Ported from HeroUI `IconChevronRight` (icons.tsx) so the default
* submenu affordance keeps the baseline artwork without adding an icon
* dependency to the component package. */
function ChevronIcon() {
return h(
"svg",
@@ -16,14 +19,19 @@ function ChevronIcon() {
"aria-hidden": "true",
fill: "none",
height: "16",
stroke: "currentColor",
"stroke-linecap": "round",
"stroke-linejoin": "round",
"stroke-width": "2",
viewBox: "0 0 24 24",
role: "presentation",
viewBox: "0 0 16 16",
width: "16",
xmlns: "http://www.w3.org/2000/svg",
},
[h("path", { d: "m9 18 6-6-6-6" })],
[
h("path", {
"clip-rule": "evenodd",
d: "M5.47 2.97a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06L9.44 8 5.47 4.03a.75.75 0 0 1 0-1.06Z",
fill: "currentColor",
"fill-rule": "evenodd",
}),
],
);
}
@@ -44,7 +52,9 @@ export default defineComponent({
{
...attrs,
"aria-hidden": "true",
class: [item.slots.value.submenuIndicator(), attrs.class],
class: item.slots.value.submenuIndicator({
class: attrs.class as never,
}),
"data-slot": "submenu-indicator",
},
slots.default ? slots.default() : ChevronIcon(),
@@ -15,6 +15,7 @@ import { menuSectionVariants } from "@heroui-vue/styles";
import {
menuContextKey,
menuSectionContextKey,
menuSectionLabelKey,
type MenuKey,
type MenuSelectionMode,
} from "../menu/context";
@@ -24,7 +25,6 @@ export default defineComponent({
name: "MenuSection",
inheritAttrs: false,
props: {
as: { type: String, default: "div" },
/** Section-level selection mode. Omit to inherit the menu's selection. */
selectionMode: {
type: String as PropType<MenuSelectionMode>,
@@ -60,11 +60,9 @@ export default defineComponent({
const acceptedKeys = computed(() =>
isControlled.value ? (props.selectedKeys ?? []) : internal.value,
);
const effectiveMode = computed<MenuSelectionMode>(() => {
if (props.selectionMode) return props.selectionMode;
if (ownsSelection.value) return "multiple";
return menuCtx?.selectionMode.value ?? "none";
});
const effectiveMode = computed<MenuSelectionMode>(
() => props.selectionMode ?? menuCtx?.selectionMode.value ?? "none",
);
const sectionSelection = useMenuSelection({
selectionMode: effectiveMode,
@@ -84,6 +82,21 @@ export default defineComponent({
},
);
// A nested Header registers here so the group keeps an accessible name.
const labelIds = ref<string[]>([]);
provide(menuSectionLabelKey, {
labelledBy: computed(() =>
labelIds.value.length ? labelIds.value.join(" ") : undefined,
),
registerLabel(id: string) {
if (!labelIds.value.includes(id))
labelIds.value = [...labelIds.value, id];
return () => {
labelIds.value = labelIds.value.filter((item) => item !== id);
};
},
});
provide(menuSectionContextKey, {
selection: {
get selectionMode() {
@@ -116,17 +129,22 @@ export default defineComponent({
},
});
return () =>
h(
return () => {
const labelledBy =
(attrs["aria-labelledby"] as string | undefined) ??
(labelIds.value.length ? labelIds.value.join(" ") : undefined);
return h(
RekaMenuGroup as never,
{
...attrs,
class: [menuSectionVariants(), attrs.class],
class: menuSectionVariants({ class: attrs.class as never }),
"aria-labelledby": labelledBy,
"data-slot": "menu-section",
role: "group",
role: (attrs.role as string | undefined) ?? "group",
},
slots,
);
};
},
});
</script>
+17 -12
View File
@@ -15,7 +15,7 @@ import {
DropdownMenuRoot as RekaDropdownMenuRoot,
injectDropdownMenuRootContext,
} from "reka-ui";
import { menuVariants } from "@heroui-vue/styles";
import { dropdownVariants, menuVariants } from "@heroui-vue/styles";
import {
dropdownContextKey,
menuCloseKey,
@@ -34,7 +34,6 @@ export default defineComponent({
name: "Menu",
inheritAttrs: false,
props: {
as: { type: String, default: "div" },
selectionMode: {
type: String as PropType<MenuSelectionMode>,
default: "none",
@@ -99,20 +98,26 @@ export default defineComponent({
selectionMode: computed(() => props.selectionMode),
});
const listNode = () =>
h(
props.as,
const listNode = () => {
// The surrounding Reka content already renders `role="menu"`; upstream
// also styles the list itself, so it stays a plain element here.
const userRole = attrs.role as string | undefined;
const rest: Record<string, unknown> = { ...attrs };
delete rest.role;
return h(
"div",
{
...attrs,
class: [dropdownCtx?.slots.value.menu(), menuVariants(), attrs.class]
.filter(Boolean)
.join(" "),
...rest,
...(userRole ? { role: userRole } : {}),
class: menuVariants({
class: [dropdownCtx?.slots.value.menu(), attrs.class],
}),
"data-selection-mode": props.selectionMode,
"data-slot": "dropdown-menu",
role: "menu",
"data-slot": dropdownCtx ? "dropdown-menu" : "menu",
},
slots,
);
};
return () => {
if (!needsOwnRoot.value) return listNode();
@@ -126,7 +131,7 @@ export default defineComponent({
h(
RekaDropdownMenuContent as never,
{
class: dropdownCtx?.slots.value.popover(),
class: dropdownVariants().popover(),
"data-slot": "dropdown-popover",
sideOffset: 0,
},
+13 -1
View File
@@ -1,4 +1,4 @@
import type { ComputedRef, InjectionKey } from "vue";
import type { ComputedRef, InjectionKey, Ref } from "vue";
export type MenuKey = string | number;
@@ -33,11 +33,23 @@ export interface MenuSectionContextValue {
export const menuSectionContextKey: InjectionKey<MenuSectionContextValue> =
Symbol("hv-menu-section");
/** MenuSection exposes this so a nested Header can name the group. */
export interface MenuSectionLabelValue {
labelledBy: ComputedRef<string | undefined>;
registerLabel: (id: string) => () => void;
}
export const menuSectionLabelKey: InjectionKey<MenuSectionLabelValue> = Symbol(
"hv-menu-section-label",
);
export interface MenuItemContextValue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
slots: ComputedRef<any>;
isDisabled: ComputedRef<boolean>;
isSelected: ComputedRef<boolean>;
isFocused: Ref<boolean>;
isPressed: Ref<boolean>;
hasSubmenu: ComputedRef<boolean>;
setHasSubmenu: (value: boolean) => void;
}