Files
heroui-vue/packages/vue/src/components/menu-item/MenuItemSubmenuIndicator.vue
T
maoyingjie 043a5418f3 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.
2026-10-24 22:14:10 +08:00

66 lines
1.7 KiB
Vue

<script lang="ts">
import {
defineComponent,
h,
inject,
onMounted,
onUnmounted,
useAttrs,
} 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",
{
"aria-hidden": "true",
fill: "none",
height: "16",
role: "presentation",
viewBox: "0 0 16 16",
width: "16",
xmlns: "http://www.w3.org/2000/svg",
},
[
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",
}),
],
);
}
export default defineComponent({
name: "MenuItemSubmenuIndicator",
inheritAttrs: false,
props: { as: { type: String, default: "span" } },
setup(props, { slots }) {
const attrs = useAttrs();
const item = inject(menuItemContextKey, null);
item?.setHasSubmenu(true);
onMounted(() => item?.setHasSubmenu(true));
onUnmounted(() => item?.setHasSubmenu(false));
return () => {
if (!item?.hasSubmenu.value) return null;
return h(
props.as,
{
...attrs,
"aria-hidden": "true",
class: item.slots.value.submenuIndicator({
class: attrs.class as never,
}),
"data-slot": "submenu-indicator",
},
slots.default ? slots.default() : ChevronIcon(),
);
};
},
});
</script>