feat: migrate AlertDialog and Drawer with reviewed overlay lifecycles
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user