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,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,