feat(ui): modals close only via Esc/X/cancel; standard 3:1 form cover processing

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-07 15:23:14 +03:30
co-authored by Cursor
parent f5b6a47f3c
commit 2f3646d085
19 changed files with 366 additions and 117 deletions
+4 -17
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onUnmounted, watch } from 'vue';
import UiIcon from '@/components/UiIcon.vue';
import { useEscClose } from '@/lib/modal-stack';
const props = withDefaults(
defineProps<{
@@ -13,33 +13,20 @@ const props = withDefaults(
const emit = defineEmits<{ close: [] }>();
function onKey(e: KeyboardEvent) {
if (e.key === 'Escape') emit('close');
}
watch(
() => props.open,
(open) => {
if (open) window.addEventListener('keydown', onKey);
else window.removeEventListener('keydown', onKey);
},
{ immediate: true },
);
onUnmounted(() => window.removeEventListener('keydown', onKey));
useEscClose(() => props.open, () => emit('close'));
</script>
<template>
<Teleport to="body">
<Transition name="ui-drawer">
<div v-if="open" class="ui-drawer-layer">
<button class="ui-drawer-dim" type="button" aria-label="بستن" @click="emit('close')" />
<div class="ui-drawer-dim" aria-hidden="true" />
<aside class="ui-drawer" role="dialog" aria-modal="true" :aria-label="title" :style="{ '--drawer-w': width }">
<header class="ui-drawer-head">
<slot name="header">
<h2>{{ title }}</h2>
</slot>
<button type="button" class="ui-drawer-close" aria-label="بستن" @click="emit('close')">
<button type="button" class="ui-drawer-close" aria-label="بستن (Esc)" title="بستن (Esc)" @click="emit('close')">
<UiIcon name="x" :size="18" />
</button>
</header>
+5 -22
View File
@@ -5,6 +5,7 @@ let openModalCount = 0;
<script setup lang="ts">
import { onUnmounted, watch } from 'vue';
import UiIcon from '@/components/UiIcon.vue';
import { useEscClose } from '@/lib/modal-stack';
const props = withDefaults(
defineProps<{
@@ -12,15 +13,9 @@ const props = withDefaults(
title: string;
/** برای مودال روی مودال (مثل انتخاب مخاطب داخل فرم) */
nest?: boolean;
/**
* بستن با کلیک روی پس‌زمینه.
* پیش‌فرض: فقط موبایل (تمام‌صفحه). در دسکتاپ عمداً بسته نمی‌شود.
*/
closeOnBackdrop?: boolean | 'mobile';
}>(),
{
nest: false,
closeOnBackdrop: 'mobile',
},
);
@@ -28,6 +23,8 @@ const emit = defineEmits<{
close: [];
}>();
useEscClose(() => props.open, () => emit('close'));
let locked = false;
function setLock(next: boolean) {
@@ -44,34 +41,20 @@ watch(
);
onUnmounted(() => setLock(false));
function isMobileViewport() {
return typeof window !== 'undefined' && window.matchMedia('(max-width: 900px)').matches;
}
function onBackdrop(event: MouseEvent) {
if (event.target !== event.currentTarget) return;
const mode = props.closeOnBackdrop;
if (mode === false) return;
if (mode === true || (mode === 'mobile' && isMobileViewport())) {
emit('close');
}
}
</script>
<template>
<Teleport to="body">
<div v-if="open" class="backdrop" :class="{ nest }" @click="onBackdrop">
<div v-if="open" class="backdrop" :class="{ nest }">
<section
class="dialog"
role="dialog"
aria-modal="true"
:aria-label="title"
@click.stop
>
<header class="head">
<h2>{{ title }}</h2>
<button type="button" class="close" aria-label="بستن" @click="emit('close')">
<button type="button" class="close" aria-label="بستن (Esc)" title="بستن (Esc)" @click="emit('close')">
<UiIcon name="x" :size="18" />
</button>
</header>