Search documentation v1.0.0

Country Select

Choose a country from a list with flags and searching functionality

Source Report Issue

Use the CountrySelect component to allow users to search and select countries from a predefined list of countries, with country icons:

Preview
  • Australia
  • United Kingdom
  • United States of America
Unlock code
How to use the CountrySelect component in Astro
<CountrySelect
name="country-select"
showSearchBar={true}
showSearchBarIcon={true}
searchBarPlaceholder="Search for your country"
whitelist={['us', 'gb', 'au']}
/>

The CountrySelect component is built on top of the Select component, meaning you can use SelectProps on your component. On top of the props of the Select component, you can also specify the following additional props on your CountrySelect:

The CountrySelect component supports 250 different flags. For optimal performance, it is recommended to either remove unused flags from your countryMap.ts file or use the whitelist prop to limit the rendered list.

Flag Type

Simply set the type prop to 4x3 to use visually smaller flag icons. By default, the aspect ratio of the flags are set to 1x1.

Default (1x1)
  • Australia
  • United Kingdom
  • United States of America
Smaller icons (4x3)
  • Australia
  • United Kingdom
  • United States of America
Unlock code
How to change flag icons
<CountrySelect
name="country-select"
showSearchBar={true}
showSearchBarIcon={true}
searchBarPlaceholder="Search for your country"
whitelist={['us', 'gb', 'au']}
type="4x3"
/>

Note that if you’re only using one type of icons, you should remove other types from your countryMap.ts.

API

Unlock code
Component API reference
type CountrySelectProps = {
type?: '4x3'
whitelist?: Array<keyof typeof countryMap>
blacklist?: Array<keyof typeof countryMap>
} & Omit<SelectProps, 'itemGroups'>
Please see the documentation of the Select component for the SelectProps type.
PropPurpose
type Set to 4x3 to change the aspect ratio of the country flags.
whitelist Specify two letter country codes to only show countries in the list.
blacklist Specify two letter country codes to omit countries from the list.