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:
@@ -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,
|
||||
}),
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user