Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Improve currency/locale/country comboboxes (#14475)
Damian Legawiec14cee85eb0ea
diff --git a/packages/dashboard-core/src/components/address-form-dialog.tsx b/packages/dashboard-core/src/components/address-form-dialog.tsxindex 4f92e38d0b..99e8c87804 100644--- a/packages/dashboard-core/src/components/address-form-dialog.tsx+++ b/packages/dashboard-core/src/components/address-form-dialog.tsx@@ -242,13 +242,18 @@ export function AddressFormDialog({<FieldError errors={[errors.address2]} /></Field><Field>- <FieldLabel>{t('admin.fields.country_code.label')}</FieldLabel>+ <FieldLabel htmlFor="addr-country">+ {t('admin.fields.country_code.label')}+ </FieldLabel><Controllername="country_code"control={form.control}render={({ field }) => (<CountryCombobox+ id="addr-country"+ invalid={!!errors.country_code}value={field.value}+ onBlur={field.onBlur}onValueChange={(iso) => {field.onChange(iso)form.setValue('state_code', '', { shouldDirty: true })@@ -270,15 +275,20 @@ export function AddressFormDialog({</Field>{useStateCombobox ? (<Field>- <FieldLabel>{t('admin.fields.state_code.label')}</FieldLabel>+ <FieldLabel htmlFor="addr-state">+ {t('admin.fields.state_code.label')}+ </FieldLabel><Controllername="state_code"control={form.control}render={({ field }) => (<StateCombobox+ id="addr-state"+ invalid={!!errors.state_code}countryCode={countryCode}states={states}value={field.value}+ onBlur={field.onBlur}onValueChange={field.onChange}/>)}diff --git a/packages/dashboard-core/src/components/country-combobox.tsx b/packages/dashboard-core/src/components/country-combobox.tsxindex 119f2bb4c8..d794ef0cc4 100644--- a/packages/dashboard-core/src/components/country-combobox.tsx+++ b/packages/dashboard-core/src/components/country-combobox.tsx@@ -1,16 +1,17 @@import {Combobox,+ ComboboxButtonTrigger,ComboboxChip,ComboboxChips,ComboboxChipsInput,ComboboxContent,ComboboxEmpty,- ComboboxInput,ComboboxItem,ComboboxList,+ ComboboxSearch,+ ComboboxTriggerPlaceholder,ComboboxValue,CountryFlag,- InputGroupAddon,useComboboxAnchor,} from '@spree/dashboard-ui'import { useCallback, useMemo, useState } from 'react'@@ -87,35 +88,51 @@ function CountryRow({ country, label }: { country: CountryOption; label: string)}+/** Maps the cached country list onto the flat option shape both pickers use. */+function useCountryOptions(): CountryOption[] {+ const { countries } = useCountries()+ return useMemo(+ () => countries.map((c) => ({ iso: c.iso, iso3: c.iso3, name: c.name })),+ [countries],+ )+}+/*** Searchable single-select country picker. Value is the 2-letter ISO code- * (so the field round-trips cleanly with the Spree API). Renders the country- * name + flag in the trigger and `<CountryRow>` in the dropdown.+ * (so the field round-trips cleanly with the Spree API).+ *+ * The field itself is a button showing the selected flag + name, with the+ * search box inside the dropdown — see `<ComboboxButtonTrigger>` for why a+ * text input is the wrong trigger for an address-adjacent picker.*/export function CountryCombobox({id,value,onValueChange,+ onBlur,placeholder,+ searchPlaceholder,+ invalid,disabled = false,}: {- /** Forwarded to the text input so a `<FieldLabel htmlFor>` can target it. */+ /** Forwarded to the trigger so a `<FieldLabel htmlFor>` can target it. */id?: stringvalue: string | null | undefinedonValueChange: (iso: string) => void+ /** Forwarded to the trigger so RHF's `<Controller>` can track touched state. */+ onBlur?: () => void+ /** Trigger text while nothing is selected. */placeholder?: string+ /** Text in the dropdown's search box. */+ searchPlaceholder?: string+ invalid?: booleandisabled?: boolean}) {const { t } = useTranslation()- const { countries } = useCountries()+ const items = useCountryOptions()const countryName = useCountryDisplayName()const filter = useCountryFilter()- const items: CountryOption[] = useMemo(- () => countries.map((c) => ({ iso: c.iso, iso3: c.iso3, name: c.name })),- [countries],- )-// The Combobox holds the selected object internally; we adapt to a flat ISO// string at the boundary so callers don't have to thread the option shape.const selected = useMemo(() => items.find((c) => c.iso === value) ?? null, [items, value])@@ -132,22 +149,29 @@ export function CountryCombobox({// "Allemagne", "Germany", "DE", or "DEU" all find the country.filter={filter}>- <ComboboxInput+ <ComboboxButtonTriggerid={id}- placeholder={placeholder ?? t('admin.components.country_combobox.search_placeholder')}+ onBlur={onBlur}disabled={disabled}+ aria-invalid={invalid || undefined}>- {/* When a country is picked the InputGroup gets a leading flag —- mirrors the dropdown items so the trigger shows the same shape.- Hidden while empty so the input doesn't lurch when typing a new- search query. */}- {selected?.iso && (- <InputGroupAddon align="inline-start">+ {selected ? (+ <><CountryFlag iso={selected.iso} />- </InputGroupAddon>+ <span className="truncate">{countryName(selected)}</span>+ </>+ ) : (+ <ComboboxTriggerPlaceholder>+ {placeholder ?? t('admin.components.country_combobox.placeholder')}+ </ComboboxTriggerPlaceholder>)}- </ComboboxInput>+ </ComboboxButtonTrigger><ComboboxContent>+ <ComboboxSearch+ placeholder={+ searchPlaceholder ?? t('admin.components.country_combobox.search_placeholder')+ }+ /><ComboboxEmpty>{t('admin.components.country_combobox.empty')}</ComboboxEmpty><ComboboxList>{(country: CountryOption) => (@@ -164,9 +188,13 @@ export function CountryCombobox({/*** Searchable multi-select country picker. Value is an array of 2-letter ISO* codes. Renders a flag + name per chip and `<CountryRow>` per dropdown row;- * filters the cached `useCountries()` list client-side via `countryFilter`- * (name + both ISO codes). Reused anywhere the admin picks multiple+ * filters the cached `useCountries()` list client-side (localized name, raw+ * name, and both ISO codes). Reused anywhere the admin picks multiple* countries (promotion Country rule, market/zone editors, …).+ *+ * Keeps the chips-with-inline-input shape rather than a button trigger: the+ * chips are the selection display, and typing beside them is how a+ * multi-select is expected to work.*/export function CountryMultiCombobox({value,@@ -184,17 +212,12 @@ export function CountryMultiCombobox({disabled?: boolean}) {const { t } = useTranslation()- const { countries } = useCountries()+ const items = useCountryOptions()const countryName = useCountryDisplayName()const filter = useCountryFilter()const anchorRef = useComboboxAnchor()const [inputValue, setInputValue] = useState('')- const items: CountryOption[] = useMemo(- () => countries.map((c) => ({ iso: c.iso, iso3: c.iso3, name: c.name })),- [countries],- )-// The Combobox holds full option objects; selection round-trips as ISO// strings. Selected ISOs not yet present in `items` (list still loading)// fall back to a stub so chips don't vanish on first render.@@ -230,13 +253,13 @@ export function CountryMultiCombobox({}</ComboboxValue><ComboboxChipsInput- placeholder={placeholder ?? t('admin.promotions.rules.country.search_placeholder')}+ placeholder={placeholder ?? t('admin.components.country_combobox.search_placeholder')}value={inputValue}onChange={(e) => setInputValue((e.target as HTMLInputElement).value)}/></ComboboxChips><ComboboxContent anchor={anchorRef}>- <ComboboxEmpty>{emptyText ?? t('admin.promotions.rules.country.empty')}</ComboboxEmpty>+ <ComboboxEmpty>{emptyText ?? t('admin.components.country_combobox.empty')}</ComboboxEmpty><ComboboxList>{(country: CountryOption) => (<ComboboxItem key={country.iso} value={country}>diff --git a/packages/dashboard-core/src/components/country-state-fields.tsx b/packages/dashboard-core/src/components/country-state-fields.tsxindex 3d016b0c6e..b96fd2b3f9 100644--- a/packages/dashboard-core/src/components/country-state-fields.tsx+++ b/packages/dashboard-core/src/components/country-state-fields.tsx@@ -1,11 +1,13 @@import type { State } from '@spree/admin-sdk'import {Combobox,+ ComboboxButtonTrigger,ComboboxContent,ComboboxEmpty,- ComboboxInput,ComboboxItem,ComboboxList,+ ComboboxSearch,+ ComboboxTriggerPlaceholder,} from '@spree/dashboard-ui'import { useMemo } from 'react'import { useTranslation } from 'react-i18next'@@ -35,23 +37,39 @@ export function useCountryStates(countryCode: string | null | undefined) {* abbreviation (e.g. "CA"). Callers should hide this and render a free-text* Input when `useCountryStates(...).states` is empty.*+ * Shares the country picker's button-trigger shape — the two sit side by side+ * in every address form, so they have to look alike, and the state field is+ * exactly as prone to being buried by the browser's saved-address panel.+ ** Keyed on `countryCode` so the internal state is reset when the country* changes — prevents a stale highlight from a previous country.*/export function StateCombobox({+ id,countryCode,states,value,onValueChange,+ onBlur,placeholder,+ searchPlaceholder,+ invalid,disabled = false,}: {+ /** Forwarded to the trigger so a `<FieldLabel htmlFor>` can target it. */+ id?: stringcountryCode: string | null | undefined/** State list for the active country (typically from `useCountryStates`). */states: Pick<State, 'abbr' | 'name'>[]value: string | null | undefinedonValueChange: (abbr: string) => void+ /** Forwarded to the trigger so RHF's `<Controller>` can track touched state. */+ onBlur?: () => void+ /** Trigger text while nothing is selected. */placeholder?: string+ /** Text in the dropdown's search box. */+ searchPlaceholder?: string+ invalid?: booleandisabled?: boolean}) {const { t } = useTranslation()@@ -66,12 +84,26 @@ export function StateCombobox({onValueChange={(s: StateOption | null) => onValueChange(s?.abbr ?? '')}itemToStringLabel={(s: StateOption | null) => s?.name ?? ''}itemToStringValue={(s: StateOption | null) => s?.abbr ?? ''}+ disabled={disabled}>- <ComboboxInput- placeholder={placeholder ?? t('admin.components.state_combobox.search_placeholder')}+ <ComboboxButtonTrigger+ id={id}+ onBlur={onBlur}disabled={disabled}- />+ aria-invalid={invalid || undefined}+ >+ {selected ? (+ <span className="truncate">{selected.name}</span>+ ) : (+ <ComboboxTriggerPlaceholder>+ {placeholder ?? t('admin.components.state_combobox.placeholder')}+ </ComboboxTriggerPlaceholder>+ )}+ </ComboboxButtonTrigger><ComboboxContent>+ <ComboboxSearch+ placeholder={searchPlaceholder ?? t('admin.components.state_combobox.search_placeholder')}+ /><ComboboxEmpty>{t('admin.components.state_combobox.empty')}</ComboboxEmpty><ComboboxList>{(state: StateOption) => (diff --git a/packages/dashboard-core/src/components/currency-select.tsx b/packages/dashboard-core/src/components/currency-select.tsxindex 7fe2e1eeb5..3eaa062ba0 100644--- a/packages/dashboard-core/src/components/currency-select.tsx+++ b/packages/dashboard-core/src/components/currency-select.tsx@@ -1,15 +1,12 @@import {Combobox,+ ComboboxButtonTrigger,ComboboxContent,ComboboxEmpty,- ComboboxInput,ComboboxItem,ComboboxList,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,+ ComboboxSearch,+ ComboboxTriggerPlaceholder,} from '@spree/dashboard-ui'import { useMemo, useState } from 'react'import { useTranslation } from 'react-i18next'@@ -47,18 +44,24 @@ interface CurrencySelectProps {* Currency codes to pick from. Defaults to the current store's* `supported_currencies`. Pass `ALL_CURRENCY_CODES` (or any custom list) for* contexts where the merchant chooses a currency the store doesn't yet- * support — e.g. a market's currency. Large lists switch to a searchable- * combobox automatically.+ * support — e.g. a market's currency.*/options?: string[]- /** Marks the field required for screen readers + native form submission. */+ /**+ * Announces the field as required to assistive technology (`aria-required`).+ * It does not enforce anything: the trigger is a button, so there is no+ * native constraint validation behind it. The consuming form owns+ * enforcement.+ */required?: booleandisabled?: boolean+ /** Text in the dropdown's search box. */+ searchPlaceholder?: string+ invalid?: boolean+ /** Forwarded to the trigger so RHF's `<Controller>` can track touched state. */+ onBlur?: () => void}-/** Above this many options a plain `<Select>` is unwieldy — switch to search. */-const SEARCHABLE_THRESHOLD = 12-/*** Picker for a currency code. Defaults to the current store's* `supported_currencies` (and the store's `default_currency`), so callers@@ -66,7 +69,11 @@ const SEARCHABLE_THRESHOLD = 12* Pass `options` (e.g. `ALL_CURRENCY_CODES`) when the merchant may pick any* currency, such as a market's currency. Each option reads `CODE — Full Name`* (e.g. `USD — US Dollar`), with the name localized to the admin UI language.- * Long option lists render a searchable combobox.+ *+ * Always searchable, whatever the list length. The picker used to fall back to+ * a plain `<Select>` under a dozen options, which meant the same field behaved+ * differently from one store to the next — typing to filter worked on a store+ * with many currencies and did nothing on a store with three.*/export function CurrencySelect({id,@@ -77,6 +84,9 @@ export function CurrencySelect({options,required,disabled,+ searchPlaceholder,+ invalid,+ onBlur,}: CurrencySelectProps) {const { t } = useTranslation()const { currencies, defaultCurrency } = useStore()@@ -120,62 +130,51 @@ export function CurrencySelect({const hiddenInput = name ? <input type="hidden" name={name} value={value} /> : null- if (items.length > SEARCHABLE_THRESHOLD) {- return (- <>- {hiddenInput}- <Combobox- items={items}- value={value}- onValueChange={(next: string | null) => handleChange(next ?? '')}- itemToStringLabel={(code: string | null) => (code ? renderOption(code) : '')}- itemToStringValue={(code: string | null) => code ?? ''}- filter={filter}- disabled={disabled}- >- <ComboboxInput- id={id}- aria-required={required}- placeholder={t('admin.components.currency_select.placeholder')}- disabled={disabled}- />- <ComboboxContent>- <ComboboxEmpty>{t('admin.components.currency_select.empty')}</ComboboxEmpty>- <ComboboxList>- {(code: string) => (- <ComboboxItem key={code} value={code}>- {renderOption(code)}- </ComboboxItem>- )}- </ComboboxList>- </ComboboxContent>- </Combobox>- </>- )- }-return (<>{/* Hidden input keeps the parent `<form>` submit / FormData path workingwithout each caller having to thread the value through state. */}{hiddenInput}- <Select value={value} onValueChange={handleChange} disabled={disabled}>- <SelectTrigger id={id} aria-required={required}>- {/* Base UI's `<SelectValue>` defaults to rendering the raw `value`- (the bare ISO code). Use the children render-prop so the- trigger shows the same `CODE — Full Name` as the items. */}- <SelectValue placeholder={t('admin.components.currency_select.placeholder')}>- {(v) => (v ? renderOption(v as string) : (v as string))}- </SelectValue>- </SelectTrigger>- <SelectContent>- {items.map((currency) => (- <SelectItem key={currency} value={currency}>- {renderOption(currency)}- </SelectItem>- ))}- </SelectContent>- </Select>+ <Combobox+ items={items}+ value={value}+ onValueChange={(next: string | null) => handleChange(next ?? '')}+ itemToStringLabel={(code: string | null) => (code ? renderOption(code) : '')}+ itemToStringValue={(code: string | null) => code ?? ''}+ filter={filter}+ disabled={disabled}+ >+ <ComboboxButtonTrigger+ id={id}+ onBlur={onBlur}+ disabled={disabled}+ aria-required={required}+ aria-invalid={invalid || undefined}+ >+ {value ? (+ <span className="truncate">{renderOption(value)}</span>+ ) : (+ <ComboboxTriggerPlaceholder>+ {t('admin.components.currency_select.placeholder')}+ </ComboboxTriggerPlaceholder>+ )}+ </ComboboxButtonTrigger>+ <ComboboxContent>+ <ComboboxSearch+ placeholder={+ searchPlaceholder ?? t('admin.components.currency_select.search_placeholder')+ }+ />+ <ComboboxEmpty>{t('admin.components.currency_select.empty')}</ComboboxEmpty>+ <ComboboxList>+ {(code: string) => (+ <ComboboxItem key={code} value={code}>+ {renderOption(code)}+ </ComboboxItem>+ )}+ </ComboboxList>+ </ComboboxContent>+ </Combobox></>)}diff --git a/packages/dashboard-core/src/components/locale-select.tsx b/packages/dashboard-core/src/components/locale-select.tsxindex 95db5c68ce..936a635b44 100644--- a/packages/dashboard-core/src/components/locale-select.tsx+++ b/packages/dashboard-core/src/components/locale-select.tsx@@ -1,19 +1,16 @@import {Combobox,+ ComboboxButtonTrigger,ComboboxChip,ComboboxChips,ComboboxChipsInput,ComboboxContent,ComboboxEmpty,- ComboboxInput,ComboboxItem,ComboboxList,+ ComboboxSearch,+ ComboboxTriggerPlaceholder,ComboboxValue,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,useComboboxAnchor,} from '@spree/dashboard-ui'import { useMemo, useState } from 'react'@@ -26,7 +23,12 @@ interface BaseProps {options?: string[]/** Locale to filter out (e.g. the default locale when picking additional supported ones). */excludeCode?: string- /** Marks the field required for screen readers + native form submission. */+ /**+ * Announces the field as required to assistive technology (`aria-required`).+ * It does not enforce anything: the trigger is a button, so there is no+ * native constraint validation behind it. The consuming form owns+ * enforcement.+ */required?: booleandisabled?: booleanplaceholder?: string@@ -34,10 +36,23 @@ interface BaseProps {id?: string}+/**+ * Single-select only, by design — the multi-select deliberately does not+ * support these. Its search box is the chips input itself rather than a box+ * inside the popup, and its validity is a property of the whole selection+ * rather than of one control. Declaring them here rather than on `BaseProps`+ * makes passing them to a `multiple` picker a compile error instead of a prop+ * that is silently dropped.+ */interface SingleProps extends BaseProps {multiple?: falsevalue: string | null | undefinedonChange: (locale: string) => void+ /** Text in the dropdown's search box. */+ searchPlaceholder?: string+ invalid?: boolean+ /** Forwarded to the trigger so RHF's `<Controller>` can track touched state. */+ onBlur?: () => void}interface MultiProps extends BaseProps {@@ -58,16 +73,16 @@ function useLocaleDisplayName() {return (code: string) => displayName(code) ?? code}-/** Mirrors `CurrencySelect`'s row format: `CODE — Localized Name`. */+/**+ * Mirrors `CurrencySelect`'s row format: `CODE — Localized Name`. Codes the+ * runtime cannot name (`Intl.DisplayNames` returns the code back, as it does+ * for `dz`) render as the bare upper-cased code rather than `DZ — dz`.+ */function formatOption(code: string, name: string) {const upper = code.toUpperCase()- return name === code ? upper : `${upper} — ${name}`+ return !name || name.toLowerCase() === code.toLowerCase() ? upper : `${upper} — ${name}`}-/** Above this many options a plain `<Select>` is unwieldy — switch to a- * searchable combobox. Matches `CurrencySelect`. */-const SEARCHABLE_THRESHOLD = 12-/*** Combobox `filter` factory shared by the single- and multi-select pickers:* case-insensitive match on both the raw code and the localized `CODE — Name`@@ -100,6 +115,11 @@ export function LocaleLabel({ code }: { code: string }) {* `Intl.DisplayNames` against the store's `default_locale`. Use this anywhere* the merchant is choosing a storefront language (market default, supported* locales list, customer preference, etc.).+ *+ * The single-select field is a button showing the current locale, with the+ * search box inside the dropdown; it is always searchable, whatever the list+ * length, so the field behaves the same on a store with three locales as on+ * one offering the full translatable set.*/export function LocaleSelect(props: LocaleSelectProps) {const { t } = useTranslation()@@ -153,52 +173,45 @@ export function LocaleSelect(props: LocaleSelectProps) {const value = props.value ?? ''const placeholder = props.placeholder ?? t('admin.components.locale_select.placeholder')- // Long lists (e.g. the full set of translatable locales) are unusable as a- // plain dropdown — switch to a searchable combobox, matching `CurrencySelect`.- if (items.length > SEARCHABLE_THRESHOLD) {- return (- <Combobox- items={items}- value={value}- onValueChange={(next: string | null) => props.onChange(next ?? '')}- itemToStringLabel={(locale: string | null) => (locale ? labelFor(locale) : '')}- itemToStringValue={(locale: string | null) => locale ?? ''}- filter={localeFilter(labelFor)}+ return (+ <Combobox+ items={items}+ value={value}+ onValueChange={(next: string | null) => props.onChange(next ?? '')}+ itemToStringLabel={(locale: string | null) => (locale ? labelFor(locale) : '')}+ itemToStringValue={(locale: string | null) => locale ?? ''}+ filter={localeFilter(labelFor)}+ disabled={props.disabled}+ >+ <ComboboxButtonTrigger+ id={props.id}+ onBlur={props.onBlur}disabled={props.disabled}+ aria-required={props.required}+ aria-invalid={props.invalid || undefined}>- <ComboboxInput id={props.id} aria-required={props.required} placeholder={placeholder} />- <ComboboxContent>- <ComboboxEmpty>{t('admin.components.locale_select.empty')}</ComboboxEmpty>- <ComboboxList>- {(locale: string) => (- <ComboboxItem key={locale} value={locale}>- {labelFor(locale)}- </ComboboxItem>- )}- </ComboboxList>- </ComboboxContent>- </Combobox>- )- }-- return (- <Select value={value} onValueChange={props.onChange} disabled={props.disabled}>- <SelectTrigger id={props.id} aria-required={props.required}>- {/* Base UI's `<SelectValue>` defaults to the raw locale code. Use- the children render-prop so the trigger shows the same- `CODE — Name` as the items. */}- <SelectValue placeholder={placeholder}>- {(v) => (v ? labelFor(v as string) : (v as string))}- </SelectValue>- </SelectTrigger>- <SelectContent>- {items.map((locale) => (- <SelectItem key={locale} value={locale}>- {labelFor(locale)}- </SelectItem>- ))}- </SelectContent>- </Select>+ {value ? (+ <span className="truncate">{labelFor(value)}</span>+ ) : (+ <ComboboxTriggerPlaceholder>{placeholder}</ComboboxTriggerPlaceholder>+ )}+ </ComboboxButtonTrigger>+ <ComboboxContent>+ <ComboboxSearch+ placeholder={+ props.searchPlaceholder ?? t('admin.components.locale_select.search_placeholder')+ }+ />+ <ComboboxEmpty>{t('admin.components.locale_select.empty')}</ComboboxEmpty>+ <ComboboxList>+ {(locale: string) => (+ <ComboboxItem key={locale} value={locale}>+ {labelFor(locale)}+ </ComboboxItem>+ )}+ </ComboboxList>+ </ComboboxContent>+ </Combobox>)}diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.jsonindex faaabc7041..f35895d370 100644--- a/packages/dashboard-core/src/locales/ar.json+++ b/packages/dashboard-core/src/locales/ar.json@@ -378,6 +378,7 @@"components": {"currency_select": {"placeholder": "اختر عملة",+ "search_placeholder": "البحث في العملات…","empty": "لم يتم العثور على عملات"},"channel_select": {@@ -395,13 +396,16 @@"locale_select": {"placeholder": "اختر لغة","multi_placeholder": "إضافة لغات…",+ "search_placeholder": "البحث في اللغات…","empty": "لم يتم العثور على لغات"},"country_combobox": {+ "placeholder": "اختر بلداً","search_placeholder": "البحث في البلدان…","empty": "لم يتم العثور على بلدان"},"state_combobox": {+ "placeholder": "اختر ولاية","search_placeholder": "البحث في الولايات…","empty": "لم يتم العثور على ولايات"},diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.jsonindex a9f95e1bbb..e24aa1a432 100644--- a/packages/dashboard-core/src/locales/de.json+++ b/packages/dashboard-core/src/locales/de.json@@ -378,6 +378,7 @@"components": {"currency_select": {"placeholder": "Währung auswählen",+ "search_placeholder": "Währungen suchen…","empty": "Keine Währungen gefunden"},"channel_select": {@@ -395,13 +396,16 @@"locale_select": {"placeholder": "Sprache auswählen","multi_placeholder": "Sprachen hinzufügen…",+ "search_placeholder": "Sprachen suchen…","empty": "Keine Sprachen gefunden"},"country_combobox": {+ "placeholder": "Land auswählen","search_placeholder": "Länder suchen…","empty": "Keine Länder gefunden"},"state_combobox": {+ "placeholder": "Bundesland auswählen","search_placeholder": "Bundesländer suchen…","empty": "Keine Bundesländer gefunden"},diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.jsonindex e580784575..72de749efe 100644--- a/packages/dashboard-core/src/locales/en.json+++ b/packages/dashboard-core/src/locales/en.json@@ -378,6 +378,7 @@"components": {"currency_select": {"placeholder": "Select a currency",+ "search_placeholder": "Search currencies…","empty": "No currencies found"},"channel_select": {@@ -395,13 +396,16 @@"locale_select": {"placeholder": "Select a locale","multi_placeholder": "Add locales…",+ "search_placeholder": "Search languages…","empty": "No locales found"},"country_combobox": {+ "placeholder": "Select a country","search_placeholder": "Search countries…","empty": "No countries found"},"state_combobox": {+ "placeholder": "Select a state","search_placeholder": "Search states…","empty": "No states found"},diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.jsonindex c7782ca82e..b9cf1a5120 100644--- a/packages/dashboard-core/src/locales/fr.json+++ b/packages/dashboard-core/src/locales/fr.json@@ -378,6 +378,7 @@"components": {"currency_select": {"placeholder": "Sélectionner une devise",+ "search_placeholder": "Rechercher des devises…","empty": "Aucune devise trouvée"},"channel_select": {@@ -395,13 +396,16 @@"locale_select": {"placeholder": "Sélectionner une langue","multi_placeholder": "Ajouter des langues…",+ "search_placeholder": "Rechercher des langues…","empty": "Aucune langue trouvée"},"country_combobox": {+ "placeholder": "Sélectionner un pays","search_placeholder": "Rechercher des pays…","empty": "Aucun pays trouvé"},"state_combobox": {+ "placeholder": "Sélectionner une région","search_placeholder": "Rechercher des régions…","empty": "Aucune région trouvée"},diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.jsonindex 517318d4a9..af0fee95e1 100644--- a/packages/dashboard-core/src/locales/pl.json+++ b/packages/dashboard-core/src/locales/pl.json@@ -378,6 +378,7 @@"components": {"currency_select": {"placeholder": "Wybierz walutę",+ "search_placeholder": "Szukaj walut…","empty": "Nie znaleziono walut"},"channel_select": {@@ -395,13 +396,16 @@"locale_select": {"placeholder": "Wybierz język","multi_placeholder": "Dodaj języki…",+ "search_placeholder": "Szukaj języków…","empty": "Nie znaleziono języków"},"country_combobox": {+ "placeholder": "Wybierz kraj","search_placeholder": "Szukaj krajów…","empty": "Nie znaleziono krajów"},"state_combobox": {+ "placeholder": "Wybierz województwo","search_placeholder": "Szukaj województw…","empty": "Nie znaleziono województw"},diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.jsonindex e378478c46..a8bae8894b 100644--- a/packages/dashboard-core/src/locales/zh-CN.json+++ b/packages/dashboard-core/src/locales/zh-CN.json@@ -378,6 +378,7 @@"components": {"currency_select": {"placeholder": "选择货币",+ "search_placeholder": "搜索货币…","empty": "未找到货币"},"channel_select": {@@ -395,13 +396,16 @@"locale_select": {"placeholder": "选择语言区域","multi_placeholder": "添加语言区域…",+ "search_placeholder": "搜索语言…","empty": "未找到语言区域"},"country_combobox": {+ "placeholder": "选择国家/地区","search_placeholder": "搜索国家/地区…","empty": "未找到国家/地区"},"state_combobox": {+ "placeholder": "选择州/省","search_placeholder": "搜索州/省…","empty": "未找到州/省"},diff --git a/packages/dashboard-ui/src/ui/combobox.tsx b/packages/dashboard-ui/src/ui/combobox.tsxindex f1efac2535..4bd3b7c8ac 100644--- a/packages/dashboard-ui/src/ui/combobox.tsx+++ b/packages/dashboard-ui/src/ui/combobox.tsx@@ -27,6 +27,82 @@ function ComboboxTrigger({ className, children, ...props }: ComboboxPrimitive.Tr)}+/**+ * Button-shaped trigger for a searchable picker: the field renders the current+ * selection (flag, formatted label) and the search box lives inside the popup,+ * next to the results it filters.+ *+ * Preferred over the editable-input trigger (`<ComboboxInput>`) whenever the+ * selection has a richer display than the raw query text. A text input has to+ * show the typed query, so it erases the selected label the moment the user+ * types, and the browser's address autofill treats a text field named after a+ * country as part of an address form and covers the list with saved addresses.+ * A button has nothing to autofill into, and the search box inside the popup+ * sits outside the form's field flow where those heuristics don't reach.+ *+ * Deliberately matches `<SelectTrigger>` so a picker sitting beside a plain+ * select is indistinguishable from it until opened.+ */+function ComboboxButtonTrigger({ className, children, ...props }: ComboboxPrimitive.Trigger.Props) {+ return (+ <ComboboxPrimitive.Trigger+ data-slot="combobox-button-trigger"+ className={cn(+ "flex w-full min-h-8.5 cursor-pointer items-center justify-between gap-1.5 rounded-lg border border-border bg-card py-1.5 pr-2 pl-2.5 text-base font-normal leading-normal text-foreground shadow-xs transition-all duration-100 ease-in-out outline-none select-none focus:border-blue-500 focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_15%,transparent)] disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-muted disabled:border-border disabled:text-muted-foreground disabled:shadow-none aria-invalid:border-destructive [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ className,+ )}+ {...props}+ >+ <span className="flex min-w-0 items-center gap-2 truncate">{children}</span>+ <ChevronDownIcon className="pointer-events-none size-4 shrink-0 text-muted-foreground" />+ </ComboboxPrimitive.Trigger>+ )+}++/**+ * Placeholder text for a `<ComboboxButtonTrigger>` with nothing selected.+ * A span rather than the trigger's own `data-placeholder`, because the+ * trigger renders arbitrary children (a flag beside a name) rather than a+ * single value string.+ */+function ComboboxTriggerPlaceholder({ className, ...props }: React.ComponentProps<'span'>) {+ return (+ <span+ data-slot="combobox-trigger-placeholder"+ className={cn('truncate text-muted-foreground', className)}+ {...props}+ />+ )+}++/**+ * Search box for a button-triggered picker, rendered at the top of the popup.+ * Autofill and spell-check are turned off across the board: this filters an+ * on-screen list, so a password manager or a saved-address panel covering it+ * is pure interference.+ */+function ComboboxSearch({ className, ...props }: ComboboxPrimitive.Input.Props) {+ return (+ <div className="border-b border-border p-1">+ <ComboboxInput+ data-slot="combobox-search"+ className={cn(+ 'min-h-8.5 border-0 shadow-none has-[[data-slot=input-group-control]:focus-visible]:border-transparent has-[[data-slot=input-group-control]:focus-visible]:shadow-none',+ className,+ )}+ autoComplete="off"+ autoCorrect="off"+ autoCapitalize="off"+ spellCheck={false}+ data-1p-ignore+ data-lpignore="true"+ showTrigger={false}+ {...props}+ />+ </div>+ )+}+function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) {return (<ComboboxPrimitive.Clear@@ -275,6 +351,7 @@ function useComboboxAnchor() {export {Combobox,+ ComboboxButtonTrigger,ComboboxChip,ComboboxChips,ComboboxChipsInput,@@ -286,8 +363,10 @@ export {ComboboxItem,ComboboxLabel,ComboboxList,+ ComboboxSearch,ComboboxSeparator,ComboboxTrigger,+ ComboboxTriggerPlaceholder,ComboboxValue,useComboboxAnchor,}diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.tsindex 12af085dd6..2516b8c000 100644--- a/packages/dashboard/e2e/helpers.ts+++ b/packages/dashboard/e2e/helpers.ts@@ -194,9 +194,8 @@ export interface AddressInput {/*** Fill the shared `<AddressFormDialog>` Sheet ("Add address" / "Edit address").- * The country picker is a Base UI Combobox; we drive it by typing into the- * input (placeholder "Search countries...") and clicking the matching option.- * Same pattern for the state combobox when the country needs one.+ * The country and state pickers are button-triggered comboboxes: open the+ * field, type into the search box inside the popup, then click the option.*/export async function fillAddressForm(page: Page, address: AddressInput) {if (address.label !== undefined) await page.locator('#addr-label').fill(address.label)@@ -207,10 +206,12 @@ export async function fillAddressForm(page: Page, address: AddressInput) {if (address.postalCode !== undefined) await page.locator('#addr-zip').fill(address.postalCode)if (address.phone !== undefined) await page.locator('#addr-phone').fill(address.phone)if (address.country) {+ await page.locator('#addr-country').click()await page.getByPlaceholder(/^search countries/i).fill(address.country)await page.getByRole('option', { name: address.country }).first().click()}if (address.state) {+ await page.locator('#addr-state').click()await page.getByPlaceholder(/^search states/i).fill(address.state)await page.getByRole('option', { name: address.state }).first().click()}diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/markets.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/markets.tsxindex d573669b11..aea65558f8 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/markets.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/markets.tsx@@ -343,7 +343,9 @@ function MarketFormFields({ form }: { form: UseFormReturn<MarketFormValues> }) {<CurrencySelectid="market-currency"required+ invalid={!!errors.currency}value={field.value}+ onBlur={field.onBlur}onChange={field.onChange}options={ALL_CURRENCY_CODES}/>@@ -366,7 +368,9 @@ function MarketFormFields({ form }: { form: UseFormReturn<MarketFormValues> }) {<LocaleSelectid="market-default-locale"required+ invalid={!!errors.default_locale}value={field.value}+ onBlur={field.onBlur}onChange={field.onChange}options={availableLocales}/>diff --git a/packages/dashboard/src/routes/setup.tsx b/packages/dashboard/src/routes/setup.tsxindex 37baaa3fb1..50e421768a 100644--- a/packages/dashboard/src/routes/setup.tsx+++ b/packages/dashboard/src/routes/setup.tsx@@ -10,12 +10,13 @@ import {import {Button,Combobox,+ ComboboxButtonTrigger,ComboboxContent,ComboboxEmpty,- ComboboxInput,ComboboxItem,ComboboxList,- ComboboxTrigger,+ ComboboxSearch,+ ComboboxTriggerPlaceholder,CountryFlag,Input,Label,@@ -328,45 +329,24 @@ function SetupForm({ token }: { token: string }) {itemToStringValue={(country: SetupCountry | null) => country?.code ?? ''}disabled={countriesQuery.isPending}>- {/* A button, not a text input. Chrome decides a field is part- of an address form from its value and its neighbours, not- just its name — "United States" sitting above Email was- enough, and no combination of autocomplete attributes- stopped the saved-address panel covering this list. There- is nothing to autofill into a button. The search box lives- inside the popup, where the address heuristics don't reach- because it is outside the form's field flow. */}- <ComboboxTrigger+ <ComboboxButtonTriggerid="setup-country-search"- className="flex min-h-8.5 w-full items-center justify-between gap-1.5 rounded-lg border border-border bg-card py-1.5 pr-2 pl-2.5 text-base leading-normal shadow-xs outline-none focus:border-blue-500 focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_15%,transparent)] aria-invalid:border-destructive"onBlur={field.onBlur}aria-invalid={!!errors.country_code || undefined}>{selectedCountry ? (- <span className="flex items-center gap-2">+ <><CountryFlag iso={selectedCountry.code} />- {selectedCountry.name}- </span>+ <span className="truncate">{selectedCountry.name}</span>+ </>) : (- <span className="text-muted-foreground">+ <ComboboxTriggerPlaceholder>{t('admin.fields.setup.country_code.placeholder')}- </span>+ </ComboboxTriggerPlaceholder>)}- </ComboboxTrigger>+ </ComboboxButtonTrigger><ComboboxContent>- <div className="border-b border-border p-1">- <ComboboxInput- className="min-h-8.5 border-0 shadow-none has-[[data-slot=input-group-control]:focus-visible]:border-transparent has-[[data-slot=input-group-control]:focus-visible]:shadow-none"- autoComplete="off"- autoCorrect="off"- autoCapitalize="off"- spellCheck={false}- data-1p-ignore- data-lpignore="true"- showTrigger={false}- placeholder={t('admin.fields.setup.country_code.placeholder')}- />- </div>+ <ComboboxSearch placeholder={t('admin.fields.setup.country_code.placeholder')} /><ComboboxEmpty>{t('admin.common.no_results')}</ComboboxEmpty><ComboboxList>{(country: SetupCountry) => (@@ -434,37 +414,23 @@ function SetupForm({ token }: { token: string }) {itemToStringLabel={(code: string | null) => (code ? currencyLabel(code) : '')}itemToStringValue={(code: string | null) => code ?? ''}>- {/* Same shape as the country field: a button trigger keeps- the browser's address autofill out, and matches the- select beside it at min-h-8.5. */}- <ComboboxTrigger+ {/* Same shape as the country field, so the two read as one+ pair of fields. */}+ <ComboboxButtonTriggerid="setup-currency-search"- className="flex min-h-8.5 w-full items-center justify-between gap-1.5 rounded-lg border border-border bg-card py-1.5 pr-2 pl-2.5 text-base leading-normal shadow-xs outline-none focus:border-blue-500 focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_15%,transparent)] aria-invalid:border-destructive"onBlur={field.onBlur}aria-invalid={!!errors.currency || undefined}>{field.value ? (- currencyLabel(field.value)+ <span className="truncate">{currencyLabel(field.value)}</span>) : (- <span className="text-muted-foreground">+ <ComboboxTriggerPlaceholder>{t('admin.fields.setup.currency.placeholder')}- </span>+ </ComboboxTriggerPlaceholder>)}- </ComboboxTrigger>+ </ComboboxButtonTrigger><ComboboxContent>- <div className="border-b border-border p-1">- <ComboboxInput- className="min-h-8.5 border-0 shadow-none has-[[data-slot=input-group-control]:focus-visible]:border-transparent has-[[data-slot=input-group-control]:focus-visible]:shadow-none"- autoComplete="off"- autoCorrect="off"- autoCapitalize="off"- spellCheck={false}- data-1p-ignore- data-lpignore="true"- showTrigger={false}- placeholder={t('admin.fields.setup.currency.placeholder')}- />- </div>+ <ComboboxSearch placeholder={t('admin.fields.setup.currency.placeholder')} /><ComboboxEmpty>{t('admin.common.no_results')}</ComboboxEmpty><ComboboxList>{(code: string) => (