Phone Input
The catnip-input-phone custom element combines a country-code picker with a native telephone text field. It uses the same integrated label, supporting-text, sizing, intent, disabled, and read-only patterns as Input, Number Input, and Dropdown. Shared field behaviour is summarised on Inputs overview.
Overview
- Value (
v-model):model-value/.modelValueis{ countryCode: string; countryIsoCode: string; phoneNumber: string } | null.countryCodeis the dial prefix (for example"+47");countryIsoCodedisambiguates shared prefixes such as"+1". - Country picker: Opens a searchable list of countries with flag, country name, and dial code. The search row stays sticky while the list scrolls. Filtering matches country name, ISO code, and dial code.
- Default country: Uses
modelValue.countryIsoCodefirst, thendefault-country-code. The default"auto"infers from browser locale and falls back toNO. - Local number: The phone-number field shows the selected dial prefix before the editable number. The editable value accepts digits, a leading
+for an international prefix, and spaces, hyphens, dots or parentheses; stored local numbers are normalized to digits. Other characters stay as typed and are flagged on blur with “Use digits only”. - International numbers: Typing or pasting a
+...phone number selects the longest matching country dial code and keeps the remaining digits in the text field. - Forms: Submitted values serialize as compact JSON, for example
{"countryCode":"+47","countryIsoCode":"NO","phoneNumber":"12345678"}. Empty phone numbers submitnull.
Live example
Guidelines
Use catnip-input-phone when a user enters a phone number that should be stored with an explicit country code. For arbitrary text, use Input. For numeric quantities, use Number Input. For choosing a country without entering a phone number, use Dropdown.
Behaviour
- State: Bind
model-value/.modelValueas{ countryCode, countryIsoCode, phoneNumber } | null.countryCodeis the dial prefix, whilecountryIsoCodekeeps countries with shared prefixes distinct. The localphoneNumberis stored as digits only; Catnip does not validate it by country. - Defaults: Use
default-country-codewhen the product context knows the expected country. Keep the defaultautofor account/profile forms where browser locale is a reasonable hint. - International entry: Users can type or paste
+47...,+44..., and similar values. The component selects the longest matching dial code and moves the remaining digits into the local number field. - Filtering: The country picker supports country names, ISO codes, and dial codes. The built-in search row is sticky inside the list; avoid adding a separate country search field around it.
Composition
- Labels:
labelprop orlabelslot;label.action/label.suffixmatch Input. - Supporting text: Pass
supporting-texton the host. Use it for format hints or validation messages such as “Include your mobile number.” - Clear button: Enable
show-clear-buttonwhen phone input is optional or frequently edited. Clearing removes the model value while keeping the current country selection visible.
Validation
V1 does not include libphonenumber or country-aware validation. Validate in the product layer when exact formatting or reachability matters, then set intent="danger" and supporting-text for errors.
Best practices
- Prefer a visible label such as Phone number over relying on placeholder copy.
- Do not store only the dial code; keep
countryIsoCodewithcountryCodeso countries sharing a dial code remain distinguishable. - Do not use the phone field for one-time passcodes, PINs, or numeric IDs; those are text inputs with different semantics.