انتقل إلى المحتوى
uiify

Modal

مربع حوار مشروط مبني على عنصر dialog الأصلي.

المتصفحات
Chrome 123+Firefox 121+Safari 17.5+
الفئة
0
الحجم المضغوط
944 B
ميزانية التخطيط القسري
0 ms
ميزانية axe
0
متوافق مع SSR
نعم
مبني على
elements/dialog
العقد المنشور
بيئة الاختبار

المختبر

Modal

مغلق

متحكّم به

تتحكّم حالة المكوّن الأب في مربع الحوار المشروط هذا بعد الإماهة.

التغييرات: 0، الحالة: مغلق

أمثلة

Sizes

size writes data-size: sm 24rem, md (default) 28rem, lg 40rem, full fills the viewport. On a phone every size except full is a bottom sheet.

Small

24rem wide.

Large

40rem wide.

import { Modal } from "@gunkin/uiify";

export default function Example() {
  return (
    <>
      <Modal id="size-sm" size="sm" title="Small" trigger="Small">
        <p>24rem wide.</p>
      </Modal>
      <Modal id="size-lg" size="lg" title="Large" trigger="Large">
        <p>40rem wide.</p>
      </Modal>
    </>
  );
}

Long content

The title, content and footer share one scroll area. Compose the parts inside ModalBody for a document-style dialog.

Terms of service

The whole document scrolls together.

Clause 1: text that makes the document taller than the screen.

Clause 2: text that makes the document taller than the screen.

Clause 3: text that makes the document taller than the screen.

Clause 4: text that makes the document taller than the screen.

Clause 5: text that makes the document taller than the screen.

Clause 6: text that makes the document taller than the screen.

Clause 7: text that makes the document taller than the screen.

Clause 8: text that makes the document taller than the screen.

Clause 9: text that makes the document taller than the screen.

Clause 10: text that makes the document taller than the screen.

Clause 11: text that makes the document taller than the screen.

Clause 12: text that makes the document taller than the screen.

Clause 13: text that makes the document taller than the screen.

Clause 14: text that makes the document taller than the screen.

Clause 15: text that makes the document taller than the screen.

Clause 16: text that makes the document taller than the screen.

Clause 17: text that makes the document taller than the screen.

Clause 18: text that makes the document taller than the screen.

Clause 19: text that makes the document taller than the screen.

Clause 20: text that makes the document taller than the screen.

Clause 21: text that makes the document taller than the screen.

Clause 22: text that makes the document taller than the screen.

Clause 23: text that makes the document taller than the screen.

Clause 24: text that makes the document taller than the screen.

Clause 25: text that makes the document taller than the screen.

Clause 26: text that makes the document taller than the screen.

Clause 27: text that makes the document taller than the screen.

Clause 28: text that makes the document taller than the screen.

Clause 29: text that makes the document taller than the screen.

Clause 30: text that makes the document taller than the screen.

import { ModalTrigger, ModalContent, ModalBody, ModalHeader, ModalTitle, ModalClose, ModalFooter } from "@gunkin/uiify";
export default function Example() {
  return <>
    <ModalTrigger target="terms">Read terms</ModalTrigger>
    <ModalContent id="terms" aria-labelledby="terms-title">
      <ModalBody>
        <ModalHeader><ModalTitle id="terms-title">Terms of service</ModalTitle><ModalClose aria-label="Close" target="terms">×</ModalClose></ModalHeader>
        {Array.from({ length: 30 }, (_, index) => <p key={index}>Clause {index + 1}: text that makes the document taller than the screen.</p>)}
        <ModalFooter><ModalClose target="terms">Done</ModalClose></ModalFooter>
      </ModalBody>
    </ModalContent>
  </>;
}

Opening a modal from a modal

Render the child Modal inside the parent. It opens on top, Escape closes only the child, focus returns to the button that opened it, and the page is dimmed once.

Edit profile

Unsaved changes are lost when you close.

Discard changes?

This cannot be undone.

import { Modal, ModalClose } from "@gunkin/uiify";

export default function Example() {
  return (
    <Modal
      id="editor"
      trigger="Edit profile"
      title="Edit profile"
      description="Unsaved changes are lost when you close."
    >
      <Modal
        id="discard"
        trigger="Discard changes"
        title="Discard changes?"
        description="This cannot be undone."
        footer={<ModalClose target="discard">Keep editing</ModalClose>}
      />
    </Modal>
  );
}

API

Modal

ModalTrigger

الخاصيةالنوعافتراضيالوصف
target*string—معرّف ModalContent الذي يفتحه هذا الزر؛ يحلّه المتصفح وقت النقر، فلا تُشغّل أي JavaScript من المكتبة.
childrenReactNode—محتوى زر التفعيل.
asTAs & NativeButtonAs<TAs>"button"مكوّن يمرّر الخصائص والمرجع إلى زر أصلي؛ تُرفض الوسوم الأخرى لأن أوامر invoker تحتاج إلى زر حقيقي.

ModalContent

الخاصيةالنوعافتراضيالوصف
id*string—معرّف فريد يوفّره المستهلك؛ يشير إليه زر التفعيل وهدف الإغلاق.
size"sm" | "md" | "lg" | "full""md"مستوى العرض (أربع وعشرون أو ثمان وعشرون أو أربعون وحدة rem). تملأ full إطار العرض. يُكتب في data-size؛ تجاوز --uiify-modal-inline-size لعرض مخصّص.
align"center" | "start""center"الموضع العمودي على الأجهزة اللوحية والمكتبية. تستخدم الهواتف لوحة سفلية إلا إذا كانت size تساوي full.
dismiss"any" | "closerequest" | "none""any"closedby: تضيف any النقر على الخلفية، وتتيح closerequest مفتاح Escape فقط، وتقتصر none على عناصر تحكمك. لا يدعم Safari خاصية closedby، لذا يغلق Escape دائمًا؛ ويتولى UIEnhance النقر على الخلفية (any) وسحب اللوحة (عند غير none).
backdrop"opaque" | "blur" | "none""opaque"معالجة الخلفية. تُكتب في data-backdrop.
childrenReactNode—محتوى مربع الحوار.

ModalClose

الخاصيةالنوعافتراضيالوصف
target*string—معرّف ModalContent الذي يغلقه هذا الزر.
childrenReactNode—محتوى زر الإغلاق.
asTAs & NativeButtonAs<TAs>"button"مكوّن يمرّر الخصائص والمرجع إلى زر أصلي؛ تُرفض الوسوم الأخرى لأن أوامر invoker تحتاج إلى زر حقيقي.

ModalHeader

الخاصيةالنوعافتراضيالوصف
childrenReactNode—صف علوي ثابت يضم العنوان والوصف وعنصر تحكم الإغلاق.

ModalTitle

الخاصيةالنوعافتراضيالوصف
childrenReactNode—اسم مربع الحوار للتقنيات المساعدة؛ أشِر إلى معرّفه من aria-labelledby.

ModalDescription

الخاصيةالنوعافتراضيالوصف
childrenReactNode—نص مساعد؛ أشِر إلى معرّفه من aria-describedby.

ModalBody

الخاصيةالنوعافتراضيالوصف
childrenReactNode—منطقة التمرير بين الترويسة والتذييل.

ModalFooter

الخاصيةالنوعافتراضيالوصف
childrenReactNode—صف إجراءات مثبت تحت الجسم.

ModalGrabber

الخاصيةالنوعافتراضيالوصف
childrenReactNode—مقبض سحب زخرفي في اللوحة السفلية على الهاتف؛ يبدأ السحب من هنا.

ModalClientContent (@gunkin/uiify/components/modal/client)

الخاصيةالنوعافتراضيالوصف
id*string—معرّف فريد يوفّره المستهلك؛ يشير إليه زر التفعيل والإغلاق.
openboolean—حالة الفتح المتحكّم بها، وهي المرجع المعتمد بعد الإماهة.
defaultOpenboolean—حالة أولية غير متحكّم بها، تُطبّق باستخدام showModal() بعد الإماهة؛ وتظل بنية الخادم مغلقة.
onOpenChange(open: boolean) => void—تُستدعى مرة لكل تغيير أصلي أو برمجي مع الحالة الجديدة، ومنها مرة عند التثبيت إذا فتحه المتصفح قبل الإماهة.
onOpenChangeComplete(open: boolean) => void—تُستدعى مرة لكل انتقال فتح أو إغلاق بعد اكتمال انتقالات CSS، أو فورًا إن لم توجد، بما فيها انتقال defaultOpen بعد الإماهة؛ ولا تُستدعى لمربع حوار لم يتغيّر.
size"sm" | "md" | "lg" | "full""md"مستوى العرض (أربع وعشرون أو ثمان وعشرون أو أربعون وحدة rem). تملأ full إطار العرض. يُكتب في data-size؛ تجاوز --uiify-modal-inline-size لعرض مخصّص.
align"center" | "start""center"الموضع العمودي على الأجهزة اللوحية والمكتبية. تستخدم الهواتف لوحة سفلية إلا إذا كانت size تساوي full.
dismiss"any" | "closerequest" | "none""any"closedby: تضيف any النقر على الخلفية، وتتيح closerequest مفتاح Escape فقط، وتقتصر none على عناصر تحكمك. لا يدعم Safari خاصية closedby، لذا يغلق Escape دائمًا؛ ويتولى UIEnhance النقر على الخلفية (any) وسحب اللوحة (عند غير none).
backdrop"opaque" | "blur" | "none""opaque"معالجة الخلفية. تُكتب في data-backdrop.
childrenReactNode—محتوى مربع الحوار.

لوحة المفاتيح

المفتاحالإجراء
Escapeالإغلاق (مربع الحوار المشروط الأعلى فقط عند التداخل)
Tabتدوير التركيز داخل مربع الحوار المشروط
Shift+Tabعكس ترتيب Tab

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

عنصر أصلي <dialog> يفتحه invoker بأمر command="show-modal" قبل تشغيل أي JavaScript. يدير المتصفح حجب بقية الصفحة وحصر التركيز وEscape وإعادة التركيز؛ ويستخدم الإغلاق request-close ليتمكن onCancel من منعه. تبقى أيقونة الإغلاق في الترويسة موجودة دائمًا. على الهواتف يظهر مربع الحوار المشروط كلوحة سفلية؛ والسحب للأسفل والنقر على الخلفية اختصاران، وليسا وسيلة الخروج الوحيدة.

نقاط التنسيق

data-uiify-modaldata-part="trigger|content|header|title|description|body|footer|grabber|close"data-size="sm|lg|full"data-align="start"data-backdrop="blur|none"--uiify-trigger-open (inside [data-uiify-modal][data-part="root"])--uiify-modal-inline-size (dialog width)
تُرجمت هذه الصفحة آليًا ولم تُراجع بعد.