Country Select
A searchable country picker built on Popover and Command that shows flag emoji, country names, and optional dial codes. It supports pinned priority countries and single or multiple selection, and matches on country name or ISO-2 code.


Installed with shadcn add · 2 workarounds · theme from registry.json
- applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
- installed base item https://hirael.com/r/theme-emerald.json (registry preview settings)
Installation
Requires @hirael in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { CountrySelect, CountrySelectTrigger, CountrySelectValue, CountrySelectContent } from '@/components/country-select';<CountrySelect defaultValue='JP'> <CountrySelectTrigger> <CountrySelectValue /> </CountrySelectTrigger> <CountrySelectContent /></CountrySelect>- Collecting a user's country for shipping, billing, residence, or locale fields where a native select is too long to scan.
- Phone number forms that need a country picker paired with a dial code (set showDialCode).
- Forms that need several countries at once, such as target markets, by setting multiple.
- Forms where common countries should appear first, using the priority prop.
Examples
Controlled single select with pinned countries and dial codes
Controlled value with React state, pinned countries at the top, and dial codes shown next to each name.
import * as React from 'react';import { CountrySelect, CountrySelectTrigger, CountrySelectValue, CountrySelectContent } from '@/components/country-select';export function ShippingCountry() { const [country, setCountry] = React.useState('JP'); return ( <CountrySelect value={country} onValueChange={setCountry} priority={['US', 'GB', 'JP']} showDialCode> <CountrySelectTrigger> <CountrySelectValue placeholder='Select a country' /> </CountrySelectTrigger> <CountrySelectContent /> </CountrySelect> );}Multiple selection with a hidden form field
Selects several countries. The name prop renders a hidden input with the comma-joined ISO codes for form submission, and countLabel customizes the summary once three or more are chosen.
import * as React from 'react';import { CountrySelect, CountrySelectTrigger, CountrySelectValue, CountrySelectContent } from '@/components/country-select';export function TargetMarkets() { const [markets, setMarkets] = React.useState<string[]>(['FR', 'DE']); return ( <CountrySelect multiple value={markets} onValueChange={setMarkets} name='markets'> <CountrySelectTrigger> <CountrySelectValue countLabel={(n) => `${n} selected`} /> </CountrySelectTrigger> <CountrySelectContent /> </CountrySelect> );}Compact flag-only trigger with custom search and list labels
Replaces the trigger content with a single flag and customizes the search placeholder and list headings and empty message.
import * as React from 'react';import { CountrySelect, CountrySelectTrigger, CountrySelectContent, CountrySelectSearch, CountrySelectList, CountrySelectFlag,} from '@/components/country-select';export function LocaleFlag() { const [locale, setLocale] = React.useState('US'); return ( <CountrySelect value={locale} onValueChange={setLocale} priority={['US', 'JP']}> <CountrySelectTrigger className='w-auto px-2'> <CountrySelectFlag iso2={locale} /> </CountrySelectTrigger> <CountrySelectContent className='w-72'> <CountrySelectSearch placeholder='Type a country' /> <CountrySelectList emptyLabel='Nothing matches.' priorityLabel='Popular' allLabel='All countries' /> </CountrySelectContent> </CountrySelect> );}API reference
Accessibility
- The trigger has role='combobox', aria-haspopup='listbox', and aria-controls pointing at the list id. The role is fixed and cannot be overridden.
- The list is a Command list (cmdk), so arrow keys move through items, Enter selects, and the search input is focused when the popover opens.
- Keyboard search matches country name and ISO-2 code (and dial code via keywords). Command loop is enabled, so navigation wraps around.
- Flag emoji are wrapped in aria-hidden spans, so screen readers announce the country name rather than the flag glyph.
- Associate a visible label with the trigger by passing id to CountrySelect and using a matching htmlFor on a Label, since the id is applied to the button.
- The chevron icon is decorative and has no accessible name. Provide a visible label or aria-label on the trigger when no label is shown.
- When name is set, a hidden input carries the selected ISO codes for native form submission. Disabled state is forwarded to the trigger button.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Country Select" component (hirael/country-select) from its shadcn registry.1. Install it with: npx shadcn@latest add @hirael/country-select2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: id, countries, priority, showDialCode, disabled, open, defaultOpen, onOpenChange, name, children, multiple, value, defaultValue, onValueChange, variant, placeholder, countLabel, align, sideOffset, placeholder, emptyLabel, priorityLabel, allLabel, country, children, iso2.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { CountrySelect, CountrySelectTrigger, CountrySelectValue, CountrySelectContent } from '@/components/country-select';<CountrySelect defaultValue='JP'> <CountrySelectTrigger> <CountrySelectValue /> </CountrySelectTrigger> <CountrySelectContent /></CountrySelect>```Files & dependencies
- registry/hirael/bases/radix/components/country-select.tsx→ components/country-select.tsx