32 lines
933 B
Vue
32 lines
933 B
Vue
<script setup lang="ts">
|
|
import { computed, watchEffect, onUnmounted, useId } from "vue";
|
|
import { DialogTitle, injectDialogRootContext } from "reka-ui";
|
|
import { useDrawer } from "./context";
|
|
defineOptions({ inheritAttrs: false });
|
|
const props = withDefaults(defineProps<{ as?: string; id?: string }>(), {
|
|
as: "h2",
|
|
});
|
|
const ctx = useDrawer();
|
|
const root = injectDialogRootContext();
|
|
const suffix = useId();
|
|
const key = Symbol();
|
|
const generated = ctx.titles.size ? `${root.titleId}-${suffix}` : root.titleId;
|
|
const id = computed(() => props.id ?? generated);
|
|
watchEffect(() => {
|
|
ctx.titles.set(key, id.value);
|
|
});
|
|
onUnmounted(() => ctx.titles.delete(key));
|
|
</script>
|
|
<template>
|
|
<DialogTitle v-if="props.id" as="span" class="sr-only" aria-hidden="true" />
|
|
<DialogTitle
|
|
v-bind="$attrs"
|
|
:as="as"
|
|
:id="id"
|
|
class="hv-drawer__heading"
|
|
data-slot="drawer-heading"
|
|
>
|
|
<slot />
|
|
</DialogTitle>
|
|
</template>
|