نظرة عامة
يكشفCollapsible عن عقود Root وTrigger وPanel الخاصة بـ Base UI. يتولى Root حالة التوسيع، ويوفر Trigger التفعيل عبر لوحة المفاتيح وعلاقة اللوحة، بينما يتولى Panel الرسوم المتحركة ومدة بقاء المحتوى.
استخدام
defaultOpen للتوسيع غير المتحكَّم فيه. استخدم open وonOpenChange عندما يمتلك التطبيق الحالة. يتلقى رد النداء القيمة المنطقية المطلوبة وتفاصيل حدث Base UI، بما في ذلك reason وevent وcancel(). يؤدي إلغاء تغيير إلى الحفاظ على الحالة الحالية. يمكن للوحة التي يتم التحكم فيها خارجيًا حذف Trigger عندما تأتي حالتها من عنصر تحكم آخر أو شرط في التطبيق.
ترث المشغّلات حالة disabled الخاصة بـ Root ويمكنها تجاوزها باستخدام الخاصية disabled الخاصة بها. يدعم المشغّل الأصلي مفتاحَي Enter وSpace ويوفر aria-expanded وaria-controls تلقائيًا. امنح كل مشغّل اسمًا ذا معنى يسهل الوصول إليه.
البنية
تخصيص أصلي
يعرض Root وPanel عنصرdiv؛ ويعرض Trigger عنصر button. يقبل كل جزء السمات الأصلية والمعالجات وclassName وstyle والمراجع وتركيب render الخاص بـ Base UI. تتلقى دوال الاستدعاء الخاصة بالفئة والنمط حالة الجزء. مرّر جميع الخصائص المتوفرة والمرجع من مكوّنات العرض المخصصة. اضبط nativeButton={false} عندما يعرض Trigger عنصرًا ليس زرًا.
تتضمن الأنواع العامة CollapsibleRootProps وCollapsibleTriggerProps وCollapsiblePanelProps وأنواع حالة الأجزاء الثلاثة، بالإضافة إلى CollapsibleRootChangeEventDetails وCollapsibleRootChangeEventReason.
الرسوم المتحركة وعمر المحتوى
تكون القيمة الافتراضية لـ Panel هيdimension="height". استخدم dimension="width" للتوسيع الأفقي وقيّد عرض المحتوى عند الحاجة. القيمة الافتراضية لـ containAnimation هي true، وهي تقص الفائض وتنسق المحتوى في عمود. اضبطها على false عندما يحتاج المحتوى إلى التجاوز أثناء الانتقال.
تختار duration الخاصة بـ Panel إعدادًا مسبقًا للسمة (instant أو fast أو normal أو slow)، وتكون القيمة الافتراضية هي normal. تؤدي تفضيلات تقليل الحركة إلى تعطيل الانتقالات.
يُزال Panel من التركيب بعد الإغلاق افتراضيًا. استخدم keepMounted للحفاظ على حالة المحتوى المحلية أثناء إخفاء اللوحة المغلقة. يتيح hiddenUntilFound لبحث الصفحة في المتصفح إظهار المحتوى المغلق، وله أولوية على keepMounted.
الإزاحة
Collapsible.Root
string | ((state: CollapsibleRootState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
boolean
افتراضي:"false"
Initial uncontrolled expansion state.
boolean
افتراضي:"false"
Default disabled state inherited by the triggers in this root.
((open: boolean, eventDetails: CollapsibleRootChangeEventDetails) => void)
Called with the requested open state and cancelable Base UI event details.
boolean
Controlled expansion state. Use defaultOpen for uncontrolled state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, CollapsibleRootState>
Replaces the root div. Forward the supplied props and ref.
CSSProperties | ((state: CollapsibleRootState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Collapsible.Trigger
string | ((state: CollapsibleTriggerState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
boolean
Disables this trigger.
boolean
افتراضي:"true"
Set to false when render replaces the native button with another element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, CollapsibleTriggerState>
Replaces the linked trigger button. Forward the supplied props and ref.
CSSProperties | ((state: CollapsibleTriggerState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Collapsible.Panel
string | ((state: CollapsiblePanelState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
boolean
افتراضي:"true"
Clips overflowing content during expansion and uses a column layout.
"height" | "width"
افتراضي:"height"
Dimension animated when the panel opens and closes.
"fast" | "instant" | "normal" | "slow"
افتراضي:"normal"
Theme timing preset for both size and opacity. Native style can customize transition timing.
Uses hidden until-found so browser page search can reveal the contents. Overrides keepMounted.
boolean
افتراضي:"false"
Keeps the closed panel mounted and hidden, preserving local content state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, CollapsiblePanelState>
Replaces the animated panel div. Forward the supplied props and ref.
CSSProperties | ((state: CollapsiblePanelState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.