---
title: "Country Picker · Ark UI — StyleX Blocks"
description: "Searchable country picker with flags, Intl-localized names, and ISO 3166-1 values — built on the accessible combobox pattern."
url: "https://stylexblocks.com/block/ark-ui/country-picker/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Country Picker block

Searchable country picker with flags, Intl-localized names, and ISO 3166-1 values — built on the accessible combobox pattern.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/block/base-ui/country-picker.md), [UI SDK](https://stylexblocks.com/block/ui-sdk/country-picker.md)
- Category: [Pickers](https://stylexblocks.com/blocks/pickers.md)
- Built with: [Combobox](https://stylexblocks.com/components/ark-ui/combobox.md)
- HTML page: https://stylexblocks.com/block/ark-ui/country-picker/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add country-picker
```

Equivalent: `npx shadcn add @stylexblocks/country-picker`. Registry item JSON: https://stylexblocks.com/r/ark-ui/country-picker.json

## Usage

```tsx
import { CountryPicker } from "#components/blocks/ark-ui/country-picker.tsx";

export function Example() {
  return (
    <CountryPicker
      name="country"
      defaultValue="NL"
      onValueChange={(code) => {
        // ISO 3166-1 alpha-2, e.g. "NL"
      }}
    />
  );
}
```

## Source

`components/blocks/ark-ui/country-picker.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { useMemo, useState } from "react";
import { useListCollection } from "@ark-ui/react/collection";
import { useFilter } from "@ark-ui/react/locale";
import { Combobox, type ComboboxVariantProps } from "#components/ui/ark-ui/combobox.tsx";
import type { StyleOverrideProps } from "#lib/recipe-props.ts";

/**
 * ISO 3166-1 alpha-2 codes (plus XK for Kosovo, which most products need).
 * Display names and sort order come from the platform via Intl, so the list
 * localizes itself and never goes stale.
 */
export const countryCodes = [
  "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA",
  "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV",
  "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU",
  "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES",
  "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM",
  "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE",
  "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
  "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY",
  "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT",
  "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU",
  "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA",
  "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM",
  "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL",
  "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE",
  "VG", "VI", "VN", "VU", "WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW",
];

export interface Country {
  /** ISO 3166-1 alpha-2 code — what your backend receives. */
  value: string;
  /** Localized display name from Intl.DisplayNames. */
  label: string;
}

/** Localized, collator-sorted country list; `locale` defaults to the runtime's. */
export function getCountries(locale?: string): Country[] {
  const displayNames = new Intl.DisplayNames(locale ? [locale] : undefined, { type: "region" });
  const collator = new Intl.Collator(locale);
  return countryCodes
    .map((value) => ({ value, label: displayNames.of(value) ?? value }))
    .sort((a, b) => collator.compare(a.label, b.label));
}

/** "NL" → 🇳🇱 via regional indicator symbols; falls back to letters on Windows. */
function flagEmoji(code: string): string {
  return String.fromCodePoint(...[...code].map((c) => 0x1f1a5 + c.charCodeAt(0)));
}

const styles = stylex.create({
  flag: {
    flexShrink: 0,
    marginInlineEnd: "0.5rem",
  },
});

export interface CountryPickerProps extends ComboboxVariantProps, StyleOverrideProps {
  label?: string;
  /** Trigger text while nothing is selected. */
  placeholder?: string;
  searchPlaceholder?: string;
  /** ISO 3166-1 alpha-2 code of the initial selection. */
  defaultValue?: string;
  /** ISO 3166-1 alpha-2 code of the controlled selection. */
  value?: string;
  onValueChange?: (code: string) => void;
  /** Posts the selected code with native form submits via a hidden input. */
  name?: string;
  /** Display-name locale; defaults to the runtime's locale. */
  locale?: string;
  /** Override the offered countries, e.g. only shipping destinations. */
  items?: Country[];
  disabled?: boolean;
}

/**
 * CountryPicker — country picker with a select-style trigger and a search
 * input inside the popup. The whole thing is one combobox machine, not a
 * Select with an input bolted in: opening moves focus to the panel's input,
 * which carries the ARIA combobox wiring (aria-expanded, aria-controls,
 * aria-activedescendant), so filtering stays screen-reader-accessible.
 * Speaks ISO 3166-1 alpha-2 on the wire; names localize through Intl.
 */
export function CountryPicker({
  label = "Country",
  placeholder = "Select country",
  searchPlaceholder = "Search countries…",
  defaultValue,
  value,
  onValueChange,
  name,
  locale,
  items,
  disabled,
  variant = "outline",
  size = "md",
  palette,
  style,
}: CountryPickerProps) {
  const countries = useMemo(() => items ?? getCountries(locale), [items, locale]);
  const [inner, setInner] = useState(defaultValue ?? "");
  const selected = value ?? inner;
  const selectedCountry = countries.find((c) => c.value === selected);

  const { contains } = useFilter({ sensitivity: "base" });
  const { collection, filter, reset } = useListCollection({
    initialItems: countries,
    itemToString: (item: Country) => item.label,
    itemToValue: (item: Country) => item.value,
    // match the localized name loosely, or the ISO code exactly
    filter: (itemText, filterText, item) =>
      contains(itemText, filterText) || item.value.toLowerCase() === filterText.toLowerCase(),
  });

  return (
    <Combobox.Root
      collection={collection}
      defaultValue={defaultValue ? [defaultValue] : undefined}
      value={value !== undefined ? (value ? [value] : []) : undefined}
      onValueChange={(details) => {
        const code = details.value[0] ?? "";
        setInner(code);
        onValueChange?.(code);
      }}
      onInputValueChange={(details) => filter(details.inputValue)}
      // the search is transient per open — a fresh panel shows every country
      onOpenChange={(details) => {
        if (details.open) reset();
      }}
      selectionBehavior="clear"
      disabled={disabled}
      variant={variant}
      size={size}
      palette={palette}
      style={style}
    >
      <Combobox.Label>{label}</Combobox.Label>
      <Combobox.Control>
        <Combobox.FieldTrigger>
          <Combobox.FieldValue placeholder={placeholder}>
            {selectedCountry ? (
              <>
                <span {...stylex.props(styles.flag)} aria-hidden="true">
                  {flagEmoji(selectedCountry.value)}
                </span>
                {selectedCountry.label}
              </>
            ) : null}
          </Combobox.FieldValue>
        </Combobox.FieldTrigger>
      </Combobox.Control>
      <Combobox.Positioner>
        <Combobox.Panel>
          <Combobox.Search placeholder={searchPlaceholder} />
          <Combobox.PanelList>
            {collection.items.map((country) => (
              <Combobox.Item key={country.value} item={country}>
                <span {...stylex.props(styles.flag)} aria-hidden="true">
                  {flagEmoji(country.value)}
                </span>
                <Combobox.ItemText>{country.label}</Combobox.ItemText>
                <Combobox.ItemIndicator />
              </Combobox.Item>
            ))}
            {collection.items.length === 0 ? (
              <Combobox.Empty>No countries found</Combobox.Empty>
            ) : null}
          </Combobox.PanelList>
        </Combobox.Panel>
      </Combobox.Positioner>
      {name ? <input type="hidden" name={name} value={selected} /> : null}
    </Combobox.Root>
  );
}
```
