Country input

SvCountryInput: a searchable checkout country picker (flag + name + dial code) emitting the ISO code, with label + required validation.

A live, editable Svelte 5 component example from the SvGrid gallery (Selection). Read the SvGrid UI component docs for the full API.

What this example shows

SvCountryInput - a production checkout field: a searchable country picker (flag + name + optional dial code) emitting the ISO code. Copy-paste ready.

Imports, features and API used

Imports: @svgrid/grid

Source code (317-country-input.svelte)

<script lang="ts">
  /**
   * SvCountryInput - a production checkout field: a searchable country picker
   * (flag + name + optional dial code) emitting the ISO code. Copy-paste ready.
   */
  import { SvCountryInput } from '@svgrid/grid'

  let country = $state<string | null>('US')
  let billing = $state<string | null>(null)
  const billingError = $derived(billing == null ? 'Select a billing country' : undefined)
</script>

<div class="wrap">
  <header>
    <h2>Country input</h2>
    <p>A searchable country picker (search by name, dial code or ISO) emitting the alpha-2 code - checkout, profiles, phone defaults.</p>
  </header>

  <form class="form" onsubmit={(e) => e.preventDefault()}>
    <label class="f">Shipping country
      <SvCountryInput value={country} showDial onChange={(v) => (country = v)} />
      <span class="val">ISO: {country ?? '-'}</span>
    </label>

    <SvCountryInput
      value={billing}
      label="Billing country"
      required
      invalid={!!billingError}
      error={billingError}
      onChange={(v) => (billing = v)}
    />
  </form>
</div>

<style>
  .wrap { padding: 20px; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
  header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
  header p { margin: 0; color: var(--sg-muted, #64748b); font-size: 13.5px; line-height: 1.5; }
  .form { display: flex; flex-direction: column; gap: 18px; }
  .f { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--sg-muted, #64748b); }
  .val { font-size: 12px; color: var(--sg-muted, #94a3b8); font-weight: 400; }
</style>

View this example on GitHub

Related documentation

Related articles

More Selection examples

  • Selection controls - List and overlay pickers: SvListBox (inline multi-select), SvDropDownList, SvComboBox (type to filter), SvAutoComplete (free text + suggestions), SvTagsInput (chips) and SvCountryInput (searchable, flags). Every popover portals out of the scroll container. Grid cell editors, standalone too.
  • List box - SvListBox: an assignee picker - inline multi-select with grouped options (departments), roving keyboard + type-ahead and a live summary.
  • Combo box - SvComboBox: a form field - type to filter a grouped, portalled list; the value must come from the list. With label + required validation.
  • Drop-down list - SvDropDownList: a status / priority toolbar with grouped options, type-ahead and animated portalled panels driving a live issue list.
  • Autocomplete - SvAutoComplete: a free-text search field with live suggestion shortcuts (any value accepted) - city search and a filter-syntax helper.