Skip to main content

CountryPicker

CountryPicker is a React Native form field for choosing a country: about 250 countries with flag emojis and international dialing codes, searchable by English or native name, ISO code or + dialing code. Country names follow the device's language. It's a Select with the country list built in, so it takes the same props: a bottom sheet on phones, a dropdown on the web, multiple selection, a clear button and the iOS, Material or web design.

No images or data files to add: flags are emoji, and the list is about 11 KB, parsed on first use.

import { CountryPicker } from 'patine-ui';
Behaves like
Loading…
<CountryPicker label="Country" value={country} onValueChange={setCountry} />

Try searching deutschland, usa, +44 or JP. The value is the ISO 3166-1 alpha-2 code, such as 'IL'. getCountry turns it into the name, flag and dialing code.

Try the props​

Behaves like
Props
presentation
locale
<CountryPicker
label="Country"
preferred={['US', 'GB', 'IL']}
value={value}
onValueChange={setValue}
locale="en"
/>

Example: where to ship​

A checkout's delivery step: the countries the shop ships to most come first, and the delivery time, price and customs note follow the country you pick.

Behaves like
Loading…
<VStack gap="md" style={{ width: '100%', maxWidth: 420 }}>
  <CountryPicker label="Ship to" preferred={['NL', 'BE', 'DE', 'FR']} value={country} onValueChange={setCountry} />
  {country && info ? (
    <Box border radius="md" padding="md" gap="xs">
      <HStack justify="space-between">
        <Text weight="medium">Standard to {getCountry(country)?.name}</Text>
        <Text weight="semibold">{info.price}</Text>
      </HStack>
      <Text size="sm" color="textSecondary">Arrives in {info.days}</Text>
    </Box>
  ) : null}
  {info?.customs ? (
    <Alert variant="warning" title="Customs may apply" description="Orders outside the EU can be charged import duty on arrival, paid to the carrier." />
  ) : null}
</VStack>

Preferred countries and dialing codes​

preferred pins countries to the top under their own header, in the order you give. showDialCode adds each country's code under its name.

Behaves like
Loading…
<CountryPicker
  label="Phone country"
  preferred={['US', 'GB', 'CA']}
  showDialCode
  value={country}
  onValueChange={setCountry}
/>

Phone numbers​

For a phone number, use PhoneField: this country list behind a flag and calling code button, with the number formatted as it's typed and stored in E.164.

Several countries​

multiple turns the field into chips, as with Select. maxSelected caps the count.

Behaves like
Loading…
<CountryPicker label="Countries you've visited" multiple value={visited} onValueChange={setVisited} />

A subset of countries​

countries limits the list to the ones you ship to, and exclude drops some. Both take ISO codes, and the list is always sorted by name.

Behaves like
Loading…
<CountryPicker label="Ship to" countries={EU_SHIPPING} value={country} onValueChange={setCountry} />

Pass countries, exclude and preferred from a constant, not a new array on every render, so the list is built once.

To pick a state and a city under the country, see the dependent selects example.

Country names in other languages​

Names come from Intl.DisplayNames in locale, the device locale by default. Search still matches the English and native names in every language. Where the JavaScript engine has no Intl.DisplayNames, names fall back to English.

Behaves like
Loading…
<CountryPicker
  label="Land"
  placeholder="Land auswählen"
  searchPlaceholder="Suchen"
  locale="de"
  value={country}
  onValueChange={setCountry}
/>

Utilities​

The country data comes from countries-list (MIT) and is exported for your own UIs, such as a flag next to a username or a dialing code in a form.

ExportDescription
getCountry(code){ code, name, nativeName?, dialCode, flag, keywords } for an ISO code in any case, or undefined
getAllCountries()Every Country, sorted by code
getCountryFlag(code)The flag emoji for an ISO code: 'jp' → 🇯🇵
getCountry('il'); // { code: 'IL', name: 'Israel', nativeName: 'יִשְׂרָאֵל', dialCode: '+972', flag: '🇮🇱', keywords: [] }

Props​

Every Select prop works, apart from the server search ones (options, loadOptions, onSearchChange, loading and the rest): the list is built in. value is a CountryCode, or CountryCode[] with multiple.

PropTypeDefaultDescription
countriesCountryCode[]allOnly these countries.
excludeCountryCode[]—Leave these out.
preferredCountryCode[]—Shown first, in this order, under their own header.
preferredLabelstring'Suggested'Header above preferred.
allCountriesLabelstring'All countries'Header above the rest when preferred is set.
showDialCodebooleanfalseShow each country's dialing code under its name.
localestringdevice localeLanguage of the country names.
placeholderstring'Select a country'Shown while nothing is selected.
searchPlaceholderstring'Search countries'Search field placeholder.
sheetPartial<SheetChromeProps>sheetProps.height: 0.8Sheet options. The sheet opens at 80% of the screen so it doesn't jump as search narrows the list.

Types​

type CountryCode = 'AD' | 'AE' | 'AF' | … ; // ISO 3166-1 alpha-2

interface Country {
code: CountryCode;
name: string; // English
nativeName?: string; // in the country's own language, when different
dialCode: string; // '+972'
flag: string; // '🇮🇱'
keywords: string[]; // aliases ('USA') and other dialing codes
}