Files
heroui-vue/apps/docs/demos/modal-dismiss-behavior.vue
T

97 lines
3.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import {
Button,
Modal,
ModalBackdrop,
ModalBody,
ModalClose,
ModalCloseTrigger,
ModalContainer,
ModalDialog,
ModalFooter,
ModalHeader,
ModalHeading,
ModalIcon,
} from "@heroui-vue/components";
import { IconInfoCircle as CircleInfo } from "@tabler/icons-vue";
</script>
<template>
<div class="flex max-w-sm flex-col gap-6">
<div class="flex flex-col gap-2">
<h3 class="text-lg font-semibold">isDismissable</h3>
<p class="text-sm text-muted">
控制是否允许通过点击遮罩关闭模态框。默认为
<code>true</code>
。设为
<code>false</code>
时需通过明确操作关闭。
</p>
<Modal>
<Button variant="secondary">打开模态框</Button>
<ModalBackdrop :isDismissable="false">
<ModalContainer>
<ModalDialog class="sm:max-w-[360px]">
<ModalCloseTrigger></ModalCloseTrigger>
<ModalHeader>
<ModalIcon class="bg-default text-foreground">
<CircleInfo aria-hidden="true" class="size-5"></CircleInfo>
</ModalIcon>
<ModalHeading>isDismissable = false</ModalHeading>
<p class="text-sm leading-5 text-muted">
点击遮罩不会关闭此模态框
</p>
</ModalHeader>
<ModalBody>
<p>
尝试点击遮罩区域——模态框不会关闭,必须使用关闭按钮或按 ESC
键关闭。
</p>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button class="w-full">关闭</Button>
</ModalClose>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</Modal>
</div>
<div class="flex flex-col gap-2">
<h3 class="text-lg font-semibold">isKeyboardDismissDisabled</h3>
<p class="text-sm text-muted">
控制是否允许通过 ESC 关闭模态框。设为
<code>true</code>
时将禁用 ESC,用户须通过明确操作关闭。
</p>
<Modal>
<Button variant="secondary">打开模态框</Button>
<ModalBackdrop isKeyboardDismissDisabled>
<ModalContainer>
<ModalDialog class="sm:max-w-[360px]">
<ModalCloseTrigger></ModalCloseTrigger>
<ModalHeader>
<ModalIcon class="bg-default text-foreground">
<CircleInfo aria-hidden="true" class="size-5"></CircleInfo>
</ModalIcon>
<ModalHeading>isKeyboardDismissDisabled = true</ModalHeading>
<p class="text-sm leading-5 text-muted">已禁用 ESC 键</p>
</ModalHeader>
<ModalBody>
<p>
按 ESC 无反应。必须使用关闭按钮或点击遮罩才能关闭此模态框。
</p>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button class="w-full">关闭</Button>
</ModalClose>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</Modal>
</div>
</div>
</template>