Skip to content

    PhoneInput

    A telephone field that pairs a searchable country dial-code selector with a national number input inside one unified raised field box. Typing filters countries by name, ISO code or dial code; submitting with name sends the combined dial-prefixed number.

    Preview

    Props

    • defaultCountry
    • size
    • placeholder
    • disabled
    • invalid
    • label
    import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
    import { PhoneInput } from "@/components/ui/phone-input"
    
    <Field className="w-full max-w-sm">
      <FieldLabel htmlFor="preview-phone-input">Phone number</FieldLabel>
      <FieldControl>
        <PhoneInput id="preview-phone-input" placeholder="(415) 555-0192" />
      </FieldControl>
    </Field>

    Usage

    When to use

    • Collect an international phone number with a country dial code in checkout, verification or profile forms.
    • Pair a searchable country picker directly beside the national phone number inside one unified field.

    When not to use

    • Collect a single fixed-country number without a country code picker. Use Input with type tel.
    • Enter an adjustable quantity or amount. Use NumberInput.

    Variants

    size

    Field height from size-element-*: sm 28px, md 32px (default), lg 36px, xl 44px on mouse.

    • sm

    • mddefault

    • lg

    • xl

    import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
    import { PhoneInput } from "@/components/ui/phone-input"
    
    <Field className="w-full max-w-sm">
      <FieldLabel htmlFor="preview-phone-input-size-sm">Phone number</FieldLabel>
      <FieldControl>
        <PhoneInput id="preview-phone-input-size-sm" size="sm" placeholder="(415) 555-0192" />
      </FieldControl>
    </Field>
    <Field className="w-full max-w-sm">
      <FieldLabel htmlFor="preview-phone-input-size-md">Phone number</FieldLabel>
      <FieldControl>
        <PhoneInput id="preview-phone-input-size-md" placeholder="(415) 555-0192" />
      </FieldControl>
    </Field>
    <Field className="w-full max-w-sm">
      <FieldLabel htmlFor="preview-phone-input-size-lg">Phone number</FieldLabel>
      <FieldControl>
        <PhoneInput id="preview-phone-input-size-lg" size="lg" placeholder="(415) 555-0192" />
      </FieldControl>
    </Field>
    <Field className="w-full max-w-sm">
      <FieldLabel htmlFor="preview-phone-input-size-xl">Phone number</FieldLabel>
      <FieldControl>
        <PhoneInput id="preview-phone-input-size-xl" size="xl" placeholder="(415) 555-0192" />
      </FieldControl>
    </Field>

    Examples

    Checkout contact

    Used only for delivery updates.

    import { Field, FieldControl, FieldDescription, FieldLabel } from "@/components/ui/field"
    import { PhoneInput } from "@/components/ui/phone-input"
    
    <Field className="w-full max-w-sm">
      <FieldLabel>Phone number</FieldLabel>
      <FieldControl>
        <PhoneInput defaultCountry="US" placeholder="(415) 555-0192" />
      </FieldControl>
      <FieldDescription>Used only for delivery updates.</FieldDescription>
    </Field>

    Restricted regions

    Limit the country selector to supported shipping regions with countries.

    import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
    import { PhoneInput } from "@/components/ui/phone-input"
    
    <Field className="w-full max-w-sm">
      <FieldLabel>Delivery phone</FieldLabel>
      <FieldControl>
        <PhoneInput defaultCountry="VN" countries={["VN", "SG", "TH", "JP", "US"]} placeholder="901 234 567" />
      </FieldControl>
    </Field>

    Invalid

    Enter a valid phone number.

    import { Field, FieldControl, FieldError, FieldLabel } from "@/components/ui/field"
    import { PhoneInput } from "@/components/ui/phone-input"
    
    <Field className="w-full max-w-sm">
      <FieldLabel>Phone number</FieldLabel>
      <FieldControl>
        <PhoneInput defaultCountry="US" defaultValue="123" />
      </FieldControl>
      <FieldError>Enter a valid phone number.</FieldError>
    </Field>

    Do and don't

    Do

    • Pair PhoneInput with a visible FieldLabel inside Field so the telephone input has an accessible name and linked error text.
    • Use defaultCountry to preselect the expected region while allowing users to switch countries.
    • Use size lg or xl on touch-first checkout screens for comfortable tapping.

    Don't

    • Don't strip or block formatting characters like spaces, dashes or parentheses while the user types.
    • Don't use NumberInput for phone numbers; phone numbers are identifiers, not quantities.
    • Don't leave out a visible label; placeholder text disappears as soon as typing begins.

    Props

    NameTypeValuesDefaultDescription
    valuestring--Controlled national phone number value.
    defaultValuestring-Initial national phone number value when uncontrolled.
    onValueChangefunction--Called with the national phone number string when the input changes.
    countrystring--Controlled ISO 3166-1 alpha-2 country code (uppercase or lowercase), such as "US" or "VN".
    defaultCountrystring-USInitial ISO 3166-1 alpha-2 country code when uncontrolled.
    onCountryChangefunction--Called with the uppercase ISO country code when the user selects another country.
    countriesreadonly string[]--Optional allowlist of ISO 3166-1 alpha-2 country codes to display in the country list.
    sizeenumsm | md | lg | xlmdField height from size-element-*: sm 28px, md 32px (default), lg 36px, xl 44px on mouse.
    placeholderstring--Hint text shown while the telephone input is empty, such as "(415) 555-0192".
    disabledboolean-falseDisables both the country selector button and the telephone input.
    readOnlyboolean-falseKeeps the telephone number readable and focusable while blocking edits and country changes.
    invalidboolean-falseSets aria-invalid on the telephone input and draws the danger border on the field box.
    requiredboolean-falseSets the native required attribute on the telephone input.
    namestring--Form field name; submits the combined dial-prefixed phone number via a hidden input.
    labelsPhoneInputLabels--Localized labels for the country selector button, search placeholder and empty search state.

    Anatomy

    PartDescription
    rootPhoneInput: the field group and the anchored country picker layer.
    groupThe unified raised field box: border-border-strong, bg-background-raised, shadow-low, radius-element and size-element-* heights, showing focus, disabled and invalid states through :has().
    triggerThe leading country selector button showing the 4:3 flag, dial code and chevron, separated from the text input by a border-border divider.
    hitAreaThe ::before touch-target extension on the country selector button up to size-target-min.
    inputThe national telephone input (type="tel", inputMode="tel") filling the rest of the field box.
    placeholderPlaceholder text inside the telephone input in secondary text color.
    contentThe searchable country picker panel anchored under the field box on a raised surface with shadow-med.
    itemA country option row in the listbox with flag, country name and dial code.
    indicatorThe check mark shown at the end of the currently selected country option.
    emptyThe status message shown when no country matches the search query.

    Accessibility

    Role: textbox

    KeysAction
    TabMoves focus between the country selector button and the telephone input.
    Enter, Space, ArrowDownOn the country selector button, opens the searchable country list and focuses its search field.
    ArrowDown, ArrowUpInside the open country list, moves the highlight through matching countries.
    EnterPicks the highlighted country, closes the list and moves focus to the telephone input.
    EscapeCloses the country list and returns focus to the country selector button.
    • Always pair with a visible FieldLabel or aria-label so the telephone input has an accessible name.
    • The phone input uses type="tel", inputMode="tel", autoComplete="tel-national" and font-size-input (16px on touch) so mobile browsers do not zoom on focus.
    • The country trigger extends its touch target to size-target-min via ::before while the native input keeps its full row height.
    • With name, a hidden input submits the full dial-prefixed phone number.

    Install

    npx werewolf-ui add https://www.werewolf-ui.dev/r/phone-input.json

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.