feat: migrate AlertDialog and Drawer with reviewed overlay lifecycles

This commit is contained in:
maoyingjie
2026-10-23 18:34:07 +08:00
parent 9f44ffb310
commit 0ec20aaa6a
83 changed files with 5871 additions and 3 deletions
@@ -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>