Files
heroui-vue/packages/vue/src/components/header/HeaderRoot.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

69 lines
1.6 KiB
Vue

<script lang="ts">
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).
* Not an application top bar with logo or navigation.
* Renders a native `<header>` by default — matching the fixed RAC contract.
*/
export default defineComponent({
name: "HeaderRoot",
inheritAttrs: false,
props: {
/** Render the root as a custom element instead of `header`. */
as: {
type: String,
default: "header",
},
},
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",
},
slots.default?.(),
);
}
return render;
},
});
</script>