Files
heroui-vue/packages/vue/src/components/menu-item/MenuItemIndicator.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

91 lines
2.3 KiB
Vue

<script lang="ts">
import { defineComponent, h, inject, useAttrs, type PropType } from "vue";
import { menuItemContextKey } from "../menu/context";
function CheckmarkIcon(selected: boolean) {
return h(
"svg",
{
"aria-hidden": "true",
"data-slot": "menu-item-indicator--checkmark",
fill: "none",
role: "presentation",
stroke: "currentColor",
"stroke-dasharray": 22,
"stroke-dashoffset": selected ? 44 : 66,
"stroke-linecap": "round",
"stroke-linejoin": "round",
"stroke-width": 2,
viewBox: "0 0 17 18",
},
[h("polyline", { points: "1 9 7 14 15 4" })],
);
}
function DotIcon() {
return h(
"svg",
{
"aria-hidden": "true",
"data-slot": "menu-item-indicator--dot",
fill: "currentColor",
"fill-rule": "evenodd",
role: "presentation",
viewBox: "0 0 16 16",
xmlns: "http://www.w3.org/2000/svg",
},
[
h("path", {
"clip-rule": "evenodd",
d: "M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14",
"fill-rule": "evenodd",
}),
],
);
}
export default defineComponent({
name: "MenuItemIndicator",
inheritAttrs: false,
props: {
as: { type: String, default: "span" },
type: {
type: String as PropType<"checkmark" | "dot">,
default: "checkmark",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const item = inject(menuItemContextKey, null);
return () => {
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(state)
: props.type === "dot"
? DotIcon()
: CheckmarkIcon(state.isSelected);
return h(
props.as,
{
...attrs,
"aria-hidden": "true",
class: item?.slots.value.indicator({ class: attrs.class as never }),
"data-slot": "menu-item-indicator",
"data-type": props.type,
"data-visible": state.isSelected || undefined,
},
content,
);
};
},
});
</script>