نظرة عامة
يجمعCurrencyPicker بين مشغّل عملة مضغوط وخيارات قابلة للبحث وقائمة منسدلة. وفّر كتالوج عملات واستخدم مكوّناً واحداً للاختيار العادي. ركّب Root وTrigger وOptions مع Dropdown عندما تحتاج النافذة المنبثقة إلى محتوى أو صفحات أخرى.
استخدام
لكل عملةcode فريد وname وخصائص symbol وdisabled اختيارية. الرمز هو معرّف الاختيار الثابت. لا يأتي المنتقي مع كتالوج عملات ولا يختار قيمة افتراضية للتطبيق.
defaultValue للاختيار غير المتحكَّم فيه. للاختيار المتحكَّم فيه، مرّر value وحدّثه من onValueChange. تتلقى دالة الاستدعاء الرمز التالي أو null وتفاصيل اختيار Dropdown التي تحتوي على event وreason وtrigger وcancel وisCanceled. استدعِ details.cancel() للحفاظ على الاختيار الحالي وإبقاء النافذة المنبثقة مفتوحة. لا يؤدي اختيار الرمز الحالي إلى إطلاق تغيير آخر.
يمسح null الاختيار. يبقى السلسلة الفارغة رمزاً صالحاً ولا تمسحه. تبقى القيمة غير المعروفة دون تغيير وتظهر كرمزها الخام في المشغّل؛ ولا تضيف خياراً إلى الكتالوج. يحدّث تعديل متحكَّم فيه لاحق أو تغيير في الكتالوج المشغّل والصف المحدد.
تركيب متقدم
يُعِدّCurrencyPicker.Root الكتالوج ويتولى الاختيار لكلا الجزأين. لا يضيف أي عنصر DOM ويجب أن يكون داخل Dropdown.Root. أبقِ Trigger وOptions تحت جذر المنتقي نفسه، بما في ذلك عندما تكون الخيارات في صفحة Dropdown أخرى. تكشف العناصر الأبناء لدالة العرض الخاصة بالجذر عن value وselectedCurrency وdisabled للتسميات والمحتوى الداعم المملوكين للمستدعي.
Root.closeOnSelect هي true؛ استخدم false لإبقاء النافذة المنبثقة مفتوحة بعد اختيار عملة. تنقل مفاتيح الأسهم وHome وEnd التركيز دون تغيير القيمة. يحدد Enter أو Space أو التنشيط بالمؤشر خياراً مفعّلاً. تبقى العملات المعطّلة مرئية ولا يمكن تحديدها.
البحث والترتيب
الخيارات قابلة للبحث افتراضياً. يتجاهل البحث المسافات البيضاء المحيطة ويطابق الرموز والأسماء والرموز التعبيرية وتسميةName (CODE) الافتراضية دون حساسية لحالة الأحرف، باستخدام القواعد نفسها في كل لغة متصفح. تستبدل getSearchText على الجذر النص القابل للبحث لكل عملة. تخصيص العرض ونص البحث مستقلان.
تحتفظ النتائج بترتيب الكتالوج. عيّن selectedFirst في الصيغة المختصرة أو الجذر لنقل العملة المحددة قبل المطابقات الأخرى. يزيل الاستعلام الذي يستبعدها صفها أيضاً. لا تنشئ القيمة غير المعروفة نتيجة محددة. تعرض النتائج الفارغة emptyLabel في منطقة حالة.
عيّن Options.searchable={false} لحذف حقل البحث. تستهدف Options.searchProps إدخال البحث الأصلي، بما في ذلك ref وrender وسمات إمكانية الوصول وvalue المتحكَّم فيه أو defaultValue غير المتحكَّم فيه. تتلقى searchProps.onValueChange الاستعلام. في الاستخدام المختصر، مرّر هذه الخيارات عبر optionsProps.
يتلقى حقل البحث التركيز عند فتح منتقي قابل للبحث. يؤدي Enter مع استعلام غير فارغ إلى تنشيط أول نتيجة مفعّلة. مع استعلام فارغ، انقل التركيز إلى خيار قبل تحديده. يظل تنشيط البحث أثناء تركيب IME والبحث الجديد عند إعادة الفتح خاضعين لعقود البحث وجلسة الصفحة المشتركة في Dropdown.
العرض والأهداف الأصلية
يعرض المشغّل الرمز المحدد افتراضياً. تتلقىrenderValue القيمة { value, selectedCurrency, disabled } لتخصيص هذا العرض دون البحث عن العملة مجدداً. تتجاوز Trigger.children عرض القيمة، ويوفر Trigger.placeholder العرض الفارغ. تخصص getOptionLabel محتوى كل خيار، مع تسمية Name (CODE) الافتراضية. تنتمي أسماء العملات ورموزها وتسمياتها ومحتوى الخيارات إلى المستدعي.
تستهدف سمات الزر الأصلية للصيغة المختصرة ومعالجات الأحداث وclassName وstyle وref وrender مشغّلها. تخصص triggerProps ذلك الزر نفسه. استخدم optionsProps لعنصر div المغلف للخيارات وsearchProps المتداخلة فيه للإدخال. تخصص contentProps النافذة المنبثقة لـ Dropdown. تنسّق open وdefaultOpen وonOpenChange حالة فتح الصيغة المختصرة.
في الاستخدام المركب، تستهدف السمات الأصلية وref وrender على Trigger زره، بينما تستهدف تلك الموجودة على Options عنصر div المغلف لها. تسمّي Options.listLabel مربع قائمة الاختيار الداخلي فقط. مرّر الخصائص وref المزوّدين من مكوّن render مخصص. لا يغيّر تنسيق الغلاف الهدف الأصلي للإدخال.
عيّن disabled في الصيغة المختصرة أو الجذر لتعطيل الفتح والبحث والاختيار. يمكن لخاصية disabled الخاصة بجزء ما تعطيل ذلك الجزء أيضاً. الاختيار قيمة للمنتقي؛ يظل إرسال النموذج الأصلي وإعادة التعيين والتحقق المطلوب والتكامل مع Field خارج واجهة برمجة التطبيقات هذه.
التسميات والتكامل مع التطبيق
القيمة الافتراضية لـsearchLabel هي Search وتوفر العنصر النائب للبحث والاسم القابل للوصول. القيمة الافتراضية لـ emptyLabel هي No results وتقبل المحتوى. وفّر تسميات المصدر المترجمة واسم مشغّل قابل للوصول وأي عنصر نائب من تطبيقك. يأخذ محتوى Dropdown اسم المشغّل ما لم تقم Dropdown.Title أو تسمية محتوى صريحة بتسميته. يأخذ مربع قائمة الاختيار عنوان Dropdown المسجل أو اسم المشغّل افتراضياً. عيّن Options.listLabel لمنح مربع القائمة هذا فقط اسماً قابلاً للوصول خاصاً به، أو مرّر optionsProps.listLabel في الاستخدام المختصر. تسمّي aria-label وaria-labelledby الأصليتان على Options غلافه فقط. يحتفظ المشغّل باسمه القابل للوصول الخاص به.
يتولى التطبيق تحرير المبلغ وتخزين العملة وتنسيقها وتحميل الكتالوج وقيمته الأولية. ينبغي لمهايئ أن يربط رموز العملات المخزنة وسلوك المسح بـ value وonValueChange، مع الحفاظ على قواعد التنسيق والبدائل في التطبيق. احتفظ بأسماء العملات والتسميات المترجمة في التطبيق.
عارض المكوّن الأمامي
تغطي تركيبات sandbox لـ React وPreact البحث والاختيار المختصر والمركب، وعناصر التحكم والخيارات المعطلة، ومراجع المشغّل، والمسح باستخدام null، والتحديثات الخارجية المتحكَّم فيها، وإعادة الفتح، واستعادة التركيز باستخدام Escape. كما تتحقق من أن مسح استعلام سابق وكتابة$ يحافظان على استعلام الرمز.
تعتمد رؤية النافذة المنبثقة وهندستها والتمرير ورفضها على دعم Dropdown والبوابة في العارض المشترك. يستخدم المنتقي ذلك التنفيذ المشترك.
الخصائص
ReactNode
Caller-owned trigger content that overrides the selected value display.
string | ((state: PopoverTriggerState) => string | undefined)
Class applied to the trigger button.
boolean
Whether committing an enabled option closes the dropdown. Defaults to true. A canceled selection never closes automatically.
Omit<DropdownContentProps, "children">
Dropdown popup props, including placement, width, and accessible attributes.
readonly CurrencyPickerOption[]
مطلوب
Available currencies in display order. Each code is a unique stable identifier; name and optional symbol are caller-owned data. A currency can be disabled.
boolean
Whether the popup is initially open when uncontrolled.
string | null
افتراضي:"null"
Initial uncontrolled currency code, or null for an empty selection. Defaults to null.
boolean
افتراضي:"false"
Disables opening, search, and every currency option.
((currency: CurrencyPickerOption) => ReactNode)
افتراضي:"Name (CODE)"
Returns caller-owned content for a currency option. Defaults to Name (CODE). Display content does not change the search text.
((currency: CurrencyPickerOption) => string)
افتراضي:"Name (CODE) and symbol"
Returns searchable text for a currency. Defaults to Name (CODE) and its optional symbol. Search trims the query and matches without case sensitivity.
string
ID forwarded to the trigger button.
boolean
افتراضي:"true"
Whether render composes a native button. Set false for a custom non-button element so Base UI supplies button interaction.
((event: DropdownDismissEvent) => void)
Called before Escape closes the popup. Call event.preventDefault() to keep it open.
((event: DropdownDismissEvent) => void)
Called before an outside press or Tab out closes the popup. Call event.preventDefault() to keep it open.
((open: boolean) => void)
Called with the next open state when the popup opens or closes.
((value: string | null, eventDetails: DropdownSelectionGroupChangeEventDetails) => void)
Called with the next code or null and cancellable Dropdown selection details: event, reason, trigger, cancel and isCanceled. Calling cancel() preserves selection and prevents automatic close. Repeated single selection does not emit a change.
boolean
Whether the popup is open. Use with onOpenChange to control it.
CurrencyPickerOptionsProps
Props for the options wrapper div, listLabel, and search behavior. Native input customization belongs in optionsProps.searchProps.
ReactNode
Trigger content displayed when the selected value is null.
Ref<HTMLButtonElement>
Ref to the trigger button, or the element composed through render.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTriggerState>
Replaces the native trigger button. Forward the supplied props and ref when rendering a custom component.
((state: CurrencyPickerState) => ReactNode)
Returns selected trigger content from { value, selectedCurrency, disabled }. The default display is the raw code, or the trigger placeholder when null. Trigger children override it.
boolean
افتراضي:"false"
Moves the matching selected currency before other results. Defaults to false, preserving catalogue order.
CSSProperties | ((state: PopoverTriggerState) => CSSProperties | undefined)
Inline styles applied to the trigger button.
CurrencyPickerTriggerProps
Props for the trigger button, including native attributes, ref, render, placeholder, and caller-owned children. These override shorthand trigger props.
string | null
Controlled currency code or null for an empty selection. Undefined leaves selection uncontrolled. Empty and unknown strings remain identifiers.
CurrencyPicker.Root
ReactNode | ((state: CurrencyPickerState) => ReactNode)
مطلوب
Picker parts and supporting content, or a render function receiving { value, selectedCurrency, disabled }. Root owns selection and prepared data without adding a DOM element.
boolean
Whether committing an enabled option closes the dropdown. Defaults to true. A canceled selection never closes automatically.
readonly CurrencyPickerOption[]
مطلوب
Available currencies in display order. Each code is a unique stable identifier; name and optional symbol are caller-owned data. A currency can be disabled.
string | null
افتراضي:"null"
Initial uncontrolled currency code, or null for an empty selection. Defaults to null.
boolean
افتراضي:"false"
Disables the trigger, search input, and every currency option.
((currency: CurrencyPickerOption) => ReactNode)
افتراضي:"Name (CODE)"
Returns caller-owned content for a currency option. Defaults to Name (CODE). Display content does not change the search text.
((currency: CurrencyPickerOption) => string)
افتراضي:"Name (CODE) and symbol"
Returns searchable text for a currency. Defaults to Name (CODE) and its optional symbol. Search trims the query and matches without case sensitivity.
((value: string | null, eventDetails: DropdownSelectionGroupChangeEventDetails) => void)
Called with the next code or null and cancellable Dropdown selection details: event, reason, trigger, cancel and isCanceled. Calling cancel() preserves selection and prevents automatic close. Repeated single selection does not emit a change.
((state: CurrencyPickerState) => ReactNode)
Returns selected trigger content from { value, selectedCurrency, disabled }. The default display is the raw code, or the trigger placeholder when null. Trigger children override it.
boolean
افتراضي:"false"
Moves the matching selected currency before other results. Defaults to false, preserving catalogue order.
string | null
Controlled currency code or null for an empty selection. Undefined leaves selection uncontrolled. Empty and unknown strings remain identifiers.
CurrencyPicker.Trigger
ReactNode
Caller-owned trigger content that overrides the selected value display.
string | ((state: PopoverTriggerState) => string | undefined)
Class applied to the trigger button.
boolean
افتراضي:"false"
Additionally disables the native trigger button. Root disabled state always takes precedence.
string
ID forwarded to the trigger button.
boolean
افتراضي:"true"
Whether render composes a native button. Set false for a custom non-button element so Base UI supplies button interaction.
ReactNode
Trigger content displayed when the selected value is null.
Ref<HTMLButtonElement>
Ref to the trigger button, or the element composed through render.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTriggerState>
Replaces the native trigger button. Forward the supplied props and ref when rendering a custom component.
CSSProperties | ((state: PopoverTriggerState) => CSSProperties | undefined)
Inline styles applied to the trigger button.
CurrencyPicker.Options
string
Class applied to the options wrapper div.
boolean
افتراضي:"false"
Additionally disables search and every currency option. Root disabled state always takes precedence.
ReactNode
افتراضي:"No results"
Content announced when no currencies match. Defaults to No results.
string
Accessible name for the selection listbox. Defaults to the registered Dropdown title or trigger name. Native accessible attributes on Options target only its wrapper.
Ref<HTMLDivElement>
Ref to the options wrapper div, or the element composed through render.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>
Replaces the non-interactive wrapper div. Forward the supplied props and ref when rendering a custom component. Use searchProps.render to customize the input.
boolean
افتراضي:"true"
Renders a search input above the options. Defaults to true.
string
افتراضي:"Search"
Search placeholder and accessible name. Defaults to Search.
DropdownSearchProps
Native input attributes, ref, render, and controlled or uncontrolled query props forwarded to Dropdown.Search. Use value with onValueChange or defaultValue.
CSSProperties
Inline styles applied to the options wrapper div.