PhoneInput

PhoneInput

HkPhoneInput is the phone-number field with a country dial-code chip riding its left edge. The chip opens a searchable country list, the number itself is the national part only, and the field sanitizes what it accepts: digits, spaces and dashes survive, everything else (a pasted +86, parentheses, stray letters) is dropped. Blurring the field emits the composed E.164 form.

  • For an address, an ID or any other free text, use HkInput.
  • For a six-digit verification code sent to a phone, use HkOtpInput.
  • If the country is fixed by the deployment, HkInput with a +86 prefix is enough.

Import

tsx
1
import { HkPhoneInput } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // PhoneInput, DialCodeEntry, DIAL_CODES
use hikari_components::prelude::*; // rsx!, VNode

The Rust form is a plain function, PhoneInput(PhoneInputProps { … }). Its country catalog is DIAL_CODES unless countries replaces it, and its chip label is dial_code.

Form rows

modelValue is the national number only — never the dial code — so a stored value stays valid when the country changes. dialCode accepts any shape ("+86", "86", "0086") and is canonicalized only for matching, so a v-model round-trip keeps the caller's spelling. label, hint and error come straight from HkInput, whose shell this field nests.

A code arrives by SMS.

That number is not reachable.

Sizes, readonly and disabled

size rides the nested field: sm / md / lg. disabled and readonly reach both the field and the chip — a read-only receiver shows a number that must be copied verbatim, and its country cannot be switched either.

Copied from the order.

The country catalog

countries scopes the list — a mainland-only deployment passes a single row, and the bundled catalog (DIAL_CODES, China first) is the default. The chip shows the resolved country's canonical +… code plus a caret; picking a row emits the dial code, emits the composed change and, in Vue, refocuses the number field so pick-then-type needs no second tap. The Rust mirror cannot move focus, so it reports the request through the controlled open / on_open_change pair instead.

API

Vue

Props

NameTypeDefaultRequired
modelValueString""—
dialCodeString"+86"—
countriesArray as PropType<readonly DialCodeEntry[]>() => DIAL_CODES—
placeholderString""—
disabledBooleanfalse—
readonlyBooleanfalse—
size<code>String as PropType<"sm" | "md" | "lg"></code>"md"—
labelStringundefined—
errorStringundefined—
hintStringundefined—
requiredBooleanfalse—
nameStringundefined—
submitOnEnterFunction as PropType<() => void>undefined—

Emits

EventPayload
update:modelValuestring
update:dialCodestring
dialchangestring
changestring
focusFocusEvent
blurFocusEvent

Rust

Props — PhoneInput

PropTypeDefaultDescription
model_valueString""The national number only — never the dial code (Vue: modelValue).
dial_codeString"+86".to_string()Dial code in any shape; kept as given, canonicalized only for matching (Vue: dialCode, default "+86").
countriesOption<Vec<DialCodeEntry>>NoneCountry catalog; None uses the bundled DIAL_CODES (Vue: countries, defaulting to the same table).
placeholderOption<String>NoneNative placeholder for the number field.
disabledboolfalse—
readonlyboolfalse—
sizeInputSizeInputSize::MediumField size step, carried into the nested HkInput.
labelOption<String>NoneCaption above the box.
errorOption<String>NoneError ink + message line.
hintOption<String>NoneSecondary message line, shown only when there is no error.
requiredboolfalse—
nameOption<String>NoneNative name for the number field.
submit_on_enterOption<EventHandler<()>>NoneSubmit intent for Enter inside the number field.
openboolfalseThe picker's disclosure state (Vue owns this internally; the mirror is controlled — see the header delta).
on_open_changeOption<EventHandler<bool>>NoneFired with the requested disclosure state when the chip is pressed.
on_inputOption<EventHandler<String>>NoneVue's update:modelValue: the sanitized national number.
on_dial_changeOption<EventHandler<String>>NoneVue's update:dialCode + dialchange (same payload, collapsed): the canonical "+86" shape.
on_changeOption<EventHandler<String>>NoneVue's change: the composed E.164 on blur ("" when the number is empty) — validate or submit without recomputing phone_format_e164.
on_focusOption<EventHandler<FocusEvent>>NoneVue's focus emit.
on_blurOption<EventHandler<FocusEvent>>NoneVue's blur emit.
classString""Host classes, appended to the root wrapper.
styleString""Host style, applied to the root wrapper.

Accessibility

  • The chip is a real <button type="button"> that publishes aria-haspopup="listbox" and aria-expanded, and it is named by the country and the localized "Choose country code" — the visible text is only the code. In the Rust mirror the panel is an inline listbox (role="listbox" with one role="option" per row, each carrying aria-selected); the Vue form opens the shared affix picker instead.
  • The number field is the nested HkInput, so it keeps that field's caption binding, error / hint line and Enter handling. In Vue the field also carries inputmode="tel" (raising the dial pad on touch devices) and maxlength="18"; the Rust mirror leaves both to the host.
  • readonly disables the chip as well as the field: a number that cannot be edited must not be re-prefixed from a different country.
  • The composed E.164 arrives on change on blur — validate or submit from that payload instead of re-deriving it, and keep the national value for your storage.
  • Scoping too aggressively has a cost: a field limited to mainland China silently rejects a +1 number a user pastes in. Keep every dispatch path phone-capable.

Related components

  • HkInput — the field shell this control nests.
  • HkSearchInput — the bare search field with a clear button.
  • HkNumberInput — the numeric field with a stepper column.
  • HkOtpInput — the one-time code the SMS delivers.