نظرة عامة
SegmentedControl هو إعداد مسبق مكوَّن من Radio وRadioGroup، مع خيارات متصلة. استخدمه لاختيار قصير ومتبادل الاستبعاد. للتنقل بين لوحات المحتوى، استخدم Tabs.
استخدام
وفّر اسمًا يمكن الوصول إليه للمجموعة باستخدامaria-label أو aria-labelledby. يحتاج كل خيار إلى سلسلة value فريدة. ينتمي التحديد إلى المجموعة؛ ولا تملك الخيارات حالة تحديد مستقلة.
defaultValue التحديد. تمتلك المجموعة التغييرات اللاحقة. أضف onValueChange إذا كنت بحاجة إلى مراقبتها دون التحكم في القيمة.
الحالة المتحكَّم بها
value في حالة التطبيق وحدِّثها في onValueChange. لا تجمع بين value وdefaultValue ولا تبدّل أوضاع الملكية بعد التركيب.
خيارات الأيقونة
aria-label. startIcon للزينة ومخفي عن التقنية المساعدة. تستخدم الخيارات ذات النص المرئي label ويمكنها أيضاً توفير startIcon. عيّن disabled على خيار لمنع تحديده، أو على المجموعة لتعطيل كل خيار.
لوحة المفاتيح والنماذج والاتجاه
يدخل Tab إلى المجموعة؛ وتنقلك مفاتيح الأسهم بين الخيارات الممكّنة وتحدّث التحديد. يتبع هذا سلوك زر الاختيار. تنقل مجموعات تحديد القائمة المنسدلة التركيز باستخدام مفاتيح الأسهم وتحدّد عند التنشيط.itemWidth="equal" هو الإعداد الافتراضي؛ استخدم content عندما ينبغي أن تحدد التسميات العروض. عيّن name لتضمين القيمة المحددة في إرسال النموذج الأصلي. يحافظ الإعداد المسبق على required وreadOnly وحالة التعطيل والتكامل مع النموذج الأصلي في RadioGroup. يتلقى onValueChange القيمة المحددة وتفاصيل حدث Base UI، بما في ذلك reason وcancel().
للمحتوى من اليمين إلى اليسار، اجمع DirectionProvider مع سمة dir مطابقة. يتحكم الموفّر في التفاعل الاتجاهي؛ وتتحكم dir في تخطيط المستند.
التكوين والخصائص الأصلية
تستهدف الخصائص الأصلية وclassName وstyle وrender وref عنصر div الخاص بالمجموعة. استخدم render لتكوين تلك المجموعة مع عنصر آخر؛ وحافظ على اسمها المتاح ودلالات مجموعة أزرار الاختيار. تعرض الخيارات عناصر span ذات role="radio" ومدخلات أزرار اختيار أصلية مخفية. لا يعيّن الإعداد المسبق أدوار علامة التبويب أو لوحة علامة التبويب. للمحتوى المخصص لأزرار الاختيار، أو الخصائص الأصلية لكل خيار، أو هدف عرض مختلف لأزرار الاختيار، كوّن Radio.Root وRadioGroup مباشرةً.
الإزاحة
string
مطلوب
Accessible group name. Supply this or
aria-labelledby.string
مطلوب
ID of an element that labels the group. Supply this or
aria-label.string | ((state: RadioGroupState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
string
The uncontrolled value of the radio button that should be initially selected.To render a controlled radio group, use the
value prop instead.boolean
افتراضي:"false"
Whether the component should ignore user interaction.
string
Identifies the form that owns the radio inputs.
Useful when the radio group is rendered outside the form.
boolean
افتراضي:"false"
Stretch the control to the width of its container.
Ref<HTMLInputElement>
A ref to access the hidden input element.
"content" | "equal"
افتراضي:"equal"
Use equal-width options or size each option to its content.
string
Identifies the field when a form is submitted.
((value: TValue, eventDetails: { reason: "none"; event: Event; cancel: () => void; allowPropagation: () => void; isCanceled: boolean; isPropagationAllowed: boolean; trigger: Element | undefined; }) => void)
Callback fired when the value changes.
readonly SegmentedControlOption<TValue>[]
مطلوب
Options with a unique string
value, a label or startIcon, and optional disabled. Icon-only options require an aria-label.boolean
افتراضي:"false"
Whether the user should be unable to select a different radio button in the group.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, RadioGroupState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.boolean
افتراضي:"false"
Whether the user must choose a value before submitting a form.
"md" | "sm"
افتراضي:"md"
Control height:
sm (24px) or md (32px).CSSProperties | ((state: RadioGroupState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
string
The controlled value of the radio item that should be currently selected.To render an uncontrolled radio group, use the
defaultValue prop instead."rectangle" | "round"
افتراضي:"round"
Shape:
round is a pill, rectangle fills its container with form-field corners.