Locale Picker
Combobox for picking a BCP 47 locale with native names, English names and country flags.
Keyboard
- ↑↓
- Open, then move through locales
- Enter
- Pick the locale
- Escape
- Close the picker
Installation
The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.
Usage
"use client"
import { useState } from "react"
import { LocalePicker } from "@/components/ui/locale-picker"
export function LanguageSetting() {
const [locale, setLocale] = useState("en-US")
return (
<LocalePicker
aria-label="Language"
value={locale}
onValueChange={setLocale}
locales={["en-US", "de-DE", "ja-JP", "pt-BR"]}
/>
)
}Examples
A short list
Pass locales to restrict choices to the specific regional BCP 47 locales your application supports.
Language tags without regions
Language-level tags such as 'de' or 'fr' display native and English names without regional country flags.
API reference
LocalePicker
A button that opens a searchable list of BCP 47 locales, showing native names, display language names, and country flags. Arrow keys navigate, Enter selects, and Escape closes the popover.
| Prop | Type | Default |
|---|---|---|
valuestringControlled BCP 47 language tag. | string | |
defaultValuestringDefault""Initial value when uncontrolled. | string | "" |
onValueChange(value: string) => voidCalled when a locale is picked. | (value: string) => void | |
localesstring[]DefaultDEFAULT_LOCALESLimits the list to these BCP 47 language tags. Defaults to 34 common global locales. | string[] | DEFAULT_LOCALES |
displayLocalestringDefault"en"Language used to format the secondary name in each option via Intl.DisplayNames. | string | "en" |
placeholderstringDefault"Select a locale"Shown while no locale is selected. | string | "Select a locale" |
searchPlaceholderstringDefault"Search locales"Placeholder for the search input. | string | "Search locales" |
showTagbooleanDefaulttrueWhether to show the monospace BCP 47 tag badge next to the names. | boolean | true |
namestringName for the hidden form input that submits the selected locale value. | string | |
disabledbooleanDefaultfalseDisables the trigger button and hidden form input. | boolean | false |
Other props go to the <button>.
locale-picker-utils
isValidLocale(tag: string): boolean; normalizeLocale(tag: string): string; getLocaleFlag(tag: string): string | null; formatLocaleNames(tag: string, displayLocale?: string): { nativeName: string; currentName: string; label: string }; listLocales(tags?: string[], displayLocale?: string): LocaleOption[]; filterLocales(options: LocaleOption[], query: string): LocaleOption[]Pure logic functions for BCP 47 tag validation, canonical normalization, country flag derivation, Intl.DisplayNames formatting, and search filtering. Import from @/lib/locale-picker-utils.