نافذة حوار

Modal

حوار منبثق متاح الوصول في React مبني على Radix: أيقونة رأس، عنوان، وصف، جسم، إجراءات تذييل، أحجام، حصر للتركيز، وEscape للإغلاق. يرث السمة والاتجاه.

يفتح Modal حواراً من مشغل، وللحوار رأس، جسم، وتذييل إجراءات. يرث الحوار السمة والاتجاه من المزود.

متى تستخدمه

استخدم Modal لمهمة قصيرة يجب إكمالها أو إلغاؤها قبل العودة إلى الصفحة: تأكيد حذف، إدخال رمز تحقق، أو مراجعة ملخص قبل الإرسال. اجعل الحوار لغرض واحد وبأدوات قليلة.

للتدفقات الثانوية الأطول، استخدم Drawer. للوحة خفيفة مثبتة على أداة، استخدم Popover.

أمثلة

حوار تأكيد

الخصائص

الخصائص التي يعرفها Modal. سمات العنصر الأصلي تمر كما هي.

<Modal>

الخاصيةالنوعالافتراضيالوصف
childrenReactNode
openboolean
defaultOpenboolean
onOpenChange(open: boolean) => void
modalboolean

<ModalTrigger>

الخاصيةالنوعالافتراضيالوصف
asChildboolean

<ModalClose>

الخاصيةالنوعالافتراضيالوصف
asChildboolean

<ModalShortcut>

الخاصيةالنوعالافتراضيالوصف
titleإلزاميreact.ReactNodeShortcut: renders ModalHeader > ModalTitle, and wraps children in ModalBody.
descriptionreact.ReactNodeShortcut: a ModalDescription at the top of the body (SDGA supporting text).
footerreact.ReactNodeShortcut: the actions, rendered in ModalFooter.

<ModalContent>

الخاصيةالنوعالافتراضيالوصف
size"default" | "full"
centeredboolean
titleإلزاميreact.ReactNodeShortcut: renders ModalHeader > ModalTitle, and wraps children in ModalBody.
descriptionreact.ReactNodeShortcut: a ModalDescription at the top of the body (SDGA supporting text).
footerreact.ReactNodeShortcut: the actions, rendered in ModalFooter.
showCloseButtonbooleanRender the corner X close button. Defaults to true. Set false for action-forcing dialogs where the user must pick a footer action.
closeLabelstringLocalized label for the close button. Defaults to "Close", or "إغلاق" when the DgaProvider locale is Arabic.
forceMounttrueUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
onOpenAutoFocus(event: Event) => voidEvent handler called when auto-focusing on open. Can be prevented.
onCloseAutoFocus(event: Event) => voidEvent handler called when auto-focusing on close. Can be prevented.
deferPointerDownOutsidebooleanWhen true, a 'pointerdown' event outside of the layered element will wait for the interaction's click event before dispatching, allowing third-party code to stop propagation of later events and cancel dismissal.
onEscapeKeyDown(event: KeyboardEvent) => voidEvent handler called when the escape key is down. Can be prevented.
onPointerDownOutside(event: PointerDownOutsideEvent) => voidEvent handler called when the a pointerdown event happens outside of the DismissableLayer. Can be prevented.
onFocusOutside(event: FocusOutsideEvent) => voidEvent handler called when the focus moves outside of the DismissableLayer. Can be prevented.
onInteractOutside(event: PointerDownOutsideEvent | FocusOutsideEvent) => voidEvent handler called when an interaction happens outside the DismissableLayer. Specifically, when a pointerdown event happens outside or focus moves outside of it. Can be prevented.
asChildboolean

<ModalHeader>

الخاصيةالنوعالافتراضيالوصف
asChildboolean
iconreact.ReactNodeOptional featured icon shown above the title in a 40px SDGA disc.

<ModalTitle>

الخاصيةالنوعالافتراضيالوصف
asChildbooleanOverride the heading element (e.g. render an <h3> instead of the default <h2>).

<ModalDescription>

الخاصيةالنوعالافتراضيالوصف
asChildbooleanOverride the element (e.g. render a <div> for richer markup).

إمكانية الوصول

يعتمد Modal على حوار Radix، ويعرض role="dialog" مع aria-modal. يحصر الحوار التركيز ما دام مفتوحاً، ويغلق بمفتاح Escape. عند الإغلاق، يعيد التركيز إلى المشغل. يربط Modal الحوار بـ ModalTitle وModalDescription، ليعلن قارئ الشاشة اسمه وغرضه.

يستخدم زر الإغلاق closeLabel اسماً متاحاً، وترث الطبقة الاتجاه والسمة من المزود.