نظرة عامة
استخدمSelect لقيمة نموذج يتم اختيارها من قائمة. يظل Dropdown واجهة برمجة التطبيقات الرئيسية الأعلى مستوى للقوائم وأدوات الاختيار واللوحات والصفحات التي تجمع بين مهام سير العمل هذه.
استخدام
الحالة غير المتحكم بها
استخدمdefaultValue لتعيين الأولوية الأولية. يتولى مكوّن الاختيار إدارة تغييرات التحديد اللاحقة.
items في Root لكي يعرض Value تسمية العنصر المحدد؛ وبدونها، يعرض المشغّل القيمة الأولية. يمكن أن تكون القيمة المحددة null عندما لا يكون هناك شيء محدد.
البنية التشريحية العربية
ركّب الأجزاء العامة داخلSelect.Root. يعرض Trigger وItem عناصرهما الفرعية فقط. أضف Icon وItemText وItemIndicator صراحةً عندما تريد السهم المتعرج والتسمية وعلامة الاختيار الافتراضية.
تُعد
Portal وList وBackdrop والأسهم والمؤشرات اختيارية. استخدم Positioner حول Popup لتحديد الموضع، بما في ذلك عند عرض النافذة المنبثقة ضمن السطر من دون بوابة.
الحالة المتحكم بها
مررvalue وحدّثه باستخدام onValueChange لإدارة الأولوية نفسها في حالة React. تتلقى دالة الاستدعاء القيمة التالية وتفاصيل الحدث.
تحديد متعدد
multiple، تكون القيمة مصفوفة. استخدم defaultValue={['en']} بدلاً من value وonValueChange لتحديد متعدد غير متحكم به. تمثّل الأنواع العامة للجذر قيمة الخيار وما إذا كان التحديد المتعدد مفعّلًا.
حالة الفتح
التحديد وظهور النافذة المنبثقة مستقلان عن بعضهما. تترك الأمثلة أعلاه ظهور النافذة المنبثقة غير متحكم به. يؤدي تحديد قيمة واحدة إلى إغلاق النافذة المنبثقة؛ بينما يبقيها التحديد المتعدد مفتوحة. استخدمdefaultOpen لتعيين ظهورها الأولي؛ وقيمته الافتراضية هي false.
مرر open وحدّثه باستخدام onOpenChange للتحكم في الظهور. يتحكم هذا المثال في النافذة المنبثقة مع ترك الأولوية المحددة غير متحكم بها.
التركيب مع حقل
غلّف قائمة الاختيار فيField.Root لربط المُشغِّل بتسمية مرئية ونص مساعد. يتولى الحقل وضع التسميات والتحقق؛ وتحتفظ قائمة الاختيار بحالة التحديد والنافذة المنبثقة الخاصة بها.
تركيب العنصر
ركّب محتوى عشوائيًا داخلItem. ضع التسمية القابلة للبحث في ItemText؛ ولا يصبح المحتوى الإضافي تسمية الكتابة الاستباقية الخاصة به. وفّر عناصر فرعية إلى Icon أو ItemIndicator لاستبدال أيقوناتهما الافتراضية، أو احذف هذه الأجزاء تمامًا.
render وclassName وstyle الخاصة بـ Base UI. على سبيل المثال، استخدم render={<Button />} على Trigger لتركيبه مع زر Twenty UI. لعنصر عرض ليس زرًا، عيّن أيضًا nativeButton={false}.
الموضع
عيّنsize="sm" أو size="md" على Trigger. ينتمي الموضع إلى Positioner؛ وتنتمي وجهة البوابة إلى Portal.
يحافظ Positioner على الإعدادات الافتراضية لـ Base UI: side="bottom" وalign="center" وsideOffset={0} وalignItemWithTrigger={true}. تنطبق محاذاة العنصر المحدد على إدخال المؤشر عند توفر مساحة كافية. عيّن alignItemWithTrigger={false} لاستخدام التموضع المرتكز باستمرار. تختار الأمثلة أعلاه align="start" وsideOffset={8} صراحةً.
Positioner أيضًا المراسي الافتراضية ودوال الإزاحة وarrowPadding وdisableAnchorTracking. تستخدم Portal حاوية البوابة الخاصة بالسمة ما لم توفر container. ينتظر container={null} محدد صراحةً حتى تصبح تلك الحاوية متاحة.
النماذج الأصلية وتفاصيل رد النداء
عيّنname على Root لتضمين القيمة المحددة في FormData. يرسل التحديد المتعدد إدخالًا واحدًا لكل قيمة محددة. يربط form حقل الإدخال المخفي بنموذج خارجي، ويمنح inputRef الوصول إلى ذلك الحقل. تحتفظ required وdisabled وautoComplete بسلوك النموذج الأصلي لـ Base UI.
يتلقى onValueChange وonOpenChange الحالة التالية وتفاصيل الحدث المصدر، بما في ذلك reason وevent الأصلي وcancel() وallowPropagation(). يمنع استدعاء cancel() تغيير الحالة الداخلية المقابل. تتطلب منك الجذور المتحكَّم بها الاستمرار في تحديث value أو open.
itemToStringLabel وitemToStringValue وisItemEqualToValue. استخدم null لتحديد مفرد فارغ ومصفوفة فارغة لتحديد متعدد فارغ.
لوحة المفاتيح
يمكن لمستخدمي لوحة المفاتيح فتح القائمة من المشغّل، والتنقل بين الخيارات باستخدام مفاتيح الأسهم، والكتابة للعثور على خيار. ينتقل Home وEnd إلى الخيارين الأول والأخير. يحدد Enter خيارًا؛ ويغلق Escape النافذة المنبثقة ويستعيد تركيز المشغّل. يبقي التحديد المتعدد النافذة المنبثقة مفتوحة أثناء تبديل الخيارات. ضع تسمية للمشغّل باستخدامSelect.Label أو اسم قابل للوصول أو Field. لا يمنح النص النائب وحده اسمًا لعنصر التحكم.
الخصائص
يتم إنشاء المرجع من الأنواع العامة للمكوّن. تُقبل أيضًا السمات الأصلية، بما في ذلك الأسماء المتاحة ومعالجات الأحداث، على الأجزاء التي تعرض عناصر.Select.Root
A ref to imperative actions.
unmount: Ends the closing phase of the select after an externally controlled closing animation finishes. CallpreventUnmountOnClose()inonOpenChangefirst, otherwise the select completes closing on its own. Whether it leaves the DOM is decided bykeepMountedon the portal.close: Closes the select imperatively when called.
Select parts sharing selection, open state and accessible relationships. Root renders no DOM node.
Whether the select popup is initially open.To render a controlled select popup, use the
open prop instead.The uncontrolled value of the select when it’s initially rendered.To render a controlled select, use the
value prop instead.Identifies the form that owns the hidden input.
Useful when the select is rendered outside the form.
Whether moving the pointer over items should highlight them.
Disabling this prop allows CSS
:hover to be differentiated from the :focus (data-highlighted) state.Custom comparison logic used to determine if a select item value matches the current selected value. Useful when item values are objects without matching referentially.
Defaults to
Object.is comparison.Data structure of the items rendered in the select popup.
When specified,
<Select.Value> renders the label of the selected item instead of the raw value.When the item values are objects (
<Select.Item value={object}>), this function converts the object value to a string representation for display in the trigger.
If the shape of the object is { value, label }, the label will be used automatically without needing to specify this prop.When the item values are objects (
<Select.Item value={object}>), this function converts the object value to a string representation for form submission.
If the shape of the object is { value, label }, the value will be used automatically without needing to specify this prop.Determines if the select enters a modal state when open.
true: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed.
true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.Receives the requested open state and unchanged Base UI event details.
Event handler called after any animations complete when the select popup is opened or closed.
((value: SelectOutputValue<Value, Multiple> | (Multiple extends true ? never : null), eventDetails: SelectRootChangeEventDetails) => void)
Receives the requested generic value and unchanged Base UI event details, including reason, event and cancel(). Multiple selection receives an array; a cleared single value is null.
Whether the user should be unable to choose a different option from the select popup.
Select.Label
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, FieldRootState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Trigger
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Whether the component renders a native
<button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectTriggerState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Value
Accepts a function that returns a
ReactNode to format the selected value.
Treat the value as read-only: in multiple mode it may be a shared frozen array
when nothing is selected.CSS class applied to the element, or a function that
returns a class based on the component’s state.
The placeholder value to display when no value is selected.
This is overridden by
children if specified, or by a null item’s label in items.ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectValueState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Icon
Trigger icon content. Defaults to the Twenty chevron; explicit children replace it.
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectIconState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Portal
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Portal destination. Defaults to the current theme container, then the document body. Explicit null waits for a container before mounting.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectPortalState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Backdrop
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectBackdropState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Positioner
Uses the upstream selected-item alignment by default. Set false to use side, align and offsets without overlapping the trigger.
Additional offset along the alignment axis in pixels.
Also accepts a function that returns the offset to read the dimensions of the anchor
and positioner elements, along with its side and alignment.The function takes a
data object parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | null
An element to position the popup against.
By default, the popup will be positioned against the trigger.
Minimum distance to maintain between the arrow and the edges of the popup.Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Determines how to handle collisions when positioning the popup.
side controls overflow on the preferred placement axis (top/bottom or left/right):'flip': keep the requested side when it fits; otherwise try the opposite side (topandbottom, orleftandright).'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.'none': do not correct side-axis overflow.
align controls overflow on the alignment axis (start/center/end):'flip': keep side, but swapstartandendwhen the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.'none': do not correct alignment-axis overflow.
fallbackAxisSide controls fallback behavior on the perpendicular axis when the
preferred axis cannot fit:'start': allow perpendicular fallback and try the logical start side first (topbeforebottom, orleftbeforerightin LTR).'end': allow perpendicular fallback and try the logical end side first (bottombeforetop, orrightbeforeleftin LTR).'none': do not fallback to the perpendicular axis.
side is 'shift', explicitly setting align only supports 'shift' or 'none'.
If align is omitted, it defaults to 'flip'.An element or a rectangle that delimits the area that the popup is confined to.
Whether to disable the popup from tracking any layout shift of its positioning anchor.
Ref to the positioning div. Native props, styles and render apply to this element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectPositionerState>
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.Which side of the anchor element to align the popup against.
May automatically change to avoid collisions.
Distance between the anchor and the popup in pixels.
Also accepts a function that returns the distance to read the dimensions of the anchor
and positioner elements, along with its side and alignment.The function takes a
data object parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
Whether to maintain the popup in the viewport after
the anchor element was scrolled out of view.
Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Popup
Popup content rendered as supplied. Compose inside Positioner and choose Portal separately.
CSS class applied to the element, or a function that
returns a class based on the component’s state.
boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)
Determines the element to focus when the select popup is closed.
false: Do not move focus.true: Move focus based on the default behavior (trigger or previously focused element).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse,touch,pen, orkeyboard). Return an element to focus,trueto use the default behavior, orfalse/undefinedto do nothing.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectPopupState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.List
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectListState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Item
Option content rendered as supplied. Compose ItemText and an optional ItemIndicator explicitly.
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Specifies the text label to use when the item is matched during keyboard text navigation.Defaults to the item text content if not provided.
Whether the component renders a native
<button> element when replacing it
via the render prop.
Set to true if the rendered element is a native button.ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectItemState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.ItemIndicator
Selected indicator content. Defaults to the Twenty check icon; explicit children replace it.
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectItemIndicatorState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.ItemText
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectItemTextState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Arrow
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectArrowState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.ScrollDownArrow
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Whether to keep the HTML element in the DOM while the select popup is not scrollable.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectScrollDownArrowState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.ScrollUpArrow
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Whether to keep the HTML element in the DOM while the select popup is not scrollable.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectScrollUpArrowState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Group
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectGroupState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.GroupLabel
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectGroupLabelState>
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.Style applied to the element, or a function that
returns a style object based on the component’s state.
Select.Separator
CSS class applied to the element, or a function that
returns a class based on the component’s state.