Country Select
CountrySelect is a Select Search over every ISO 3166-1 country. Names come from Intl.DisplayNames, so pass locale to translate and sort them. Pass preferredCountries to list those codes first, and showFlags for a flag beside each country. The first select does both, for GB and US. The second is limited to six countries and named in German. Search by name or by code.
@dentil/country-selectOn this page
Result:
—Result:
—components/demos/country-select-overview.tsx
'use client';
import { useState } from 'react';
import { CountrySelect } from '@/components/dentil/country-select/country-select';
export function CountrySelectOverviewDemo() {
const [country, setCountry] = useState('');
const [shipsTo, setShipsTo] = useState('');
return (
<div className="grid w-full max-w-xl gap-4 sm:grid-cols-2">
<div className="flex flex-col gap-2">
<CountrySelect value={country} onChange={setCountry} preferredCountries={['GB', 'US']} showFlags />
<span className="text-muted-foreground text-sm">
Result: <code className="text-foreground">{country || '—'}</code>
</span>
</div>
<div className="flex flex-col gap-2">
<CountrySelect
value={shipsTo}
onChange={setShipsTo}
allowedCountries={['GB', 'IE', 'FR', 'DE', 'NL', 'ES']}
locale="de"
placeholder="Lieferland"
/>
<span className="text-muted-foreground text-sm">
Result: <code className="text-foreground">{shipsTo || '—'}</code>
</span>
</div>
</div>
);
}Installation
pnpm dlx shadcn@latest add @dentil/country-selectnpx shadcn@latest add @dentil/country-selectyarn dlx shadcn@latest add @dentil/country-selectbunx --bun shadcn@latest add @dentil/country-selectFiles land in components/dentil/country-select/. It installs @dentil/select-search and country-flag-icons. Country names come from Intl.DisplayNames, not a data file.
API reference
CountrySelect
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | null | undefined | — | ISO 3166-1 alpha-2 code, e.g. GB. |
| onChange | (value: string) => void | — | Called with the picked code. |
| allowedCountries | string[] | — | Only list these codes. Lists all 250 when omitted. |
| preferredCountries | string[] | — | ISO codes listed first, in this order. A separator sits under them until the search field has text. Unknown codes are ignored. |
| showFlags | boolean | false | Draws a flag beside each country, in the list and on the trigger. Same icons as Phone Input. |
| locale | string | 'en' | Locale for country names and sort order, from Intl.DisplayNames. |
| …props | SelectSearchProps | — | Any SelectSearch prop except options, such as placeholder and emptyText. |