Skip to content
Back

Phone input

A phone field with a searchable country picker, formatting as you type and E.164 out; paste an international number and the country follows.

oxyn add phone-input
MCP
We text a code to this number
Dioxus
rsx! {
    PhoneInput {
        label: "Phone",
        value: phone(),
        description: "We text a code to this number",
        on_change: move |e164: String| phone.set(e164),
    }
}

Rendered from Rust at build time · goes live when visible

When to use

  • A number for SMS codes, a contact card, a voice agent's callback.
  • The user types it the way they know it, and the app needs E.164.

When not to use

  • One input for every form: use Text Field instead.
  • Pick one or many from a searchable, grouped list: use Combobox instead.
  • Paste a signature or messy notes and the agent fills a contact form field by field, with confidence, source highlights, review and Undo: use Form autofill instead.

Installation

Phone input is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add phone-input
Rust
use crate::oxyn::{PhoneInput, PRIMITIVES_CSS};

Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{PhoneInput, PRIMITIVES_CSS};

Usage

Dioxus · rust
rsx! {
    PhoneInput {
        label: "Phone",
        value: phone(),
        description: "We text a code to this number",
        on_change: move |e164: String| phone.set(e164),
    }
}

Examples

Us

Formatted with a valid check.

We text a code to this number
Code
rsx! {
    PhoneInput {
        label: "Phone",
        value: phone(),
        description: "We text a code to this number",
        on_change: move |e164: String| phone.set(e164),
    }
}

Picker

The country picker open.

🇺🇸United States+1
🇨🇦Canada+1
🇬🇧United Kingdom+44
🇺🇸United States+1
🇨🇦Canada+1
🇬🇧United Kingdom+44
🇮🇪Ireland+353
🇫🇷France+33
🇩🇪Germany+49
🇪🇸Spain+34
🇮🇹Italy+39
🇳🇱Netherlands+31
🇸🇪Sweden+46
🇨🇭Switzerland+41
🇵🇱Poland+48
🇵🇹Portugal+351
🇹🇷Türkiye+90
🇦🇪United Arab Emirates+971
🇸🇦Saudi Arabia+966
🇵🇰Pakistan+92
🇮🇳India+91
🇧🇩Bangladesh+880
🇨🇳China+86
🇯🇵Japan+81
🇰🇷South Korea+82
🇸🇬Singapore+65
🇮🇩Indonesia+62
🇦🇺Australia+61
🇳🇿New Zealand+64
🇧🇷Brazil+55
🇲🇽Mexico+52
🇦🇷Argentina+54
🇿🇦South Africa+27
🇳🇬Nigeria+234
🇪🇬Egypt+20
We text a code to this number
Code
rsx! {
    PhoneInput {
        label: "Phone",
        value: phone(),
        description: "We text a code to this number",
        on_change: move |e164: String| phone.set(e164),
    }
}

Uk trunk

A UK number keeps the typed 0.

We text a code to this number
Code
rsx! {
    PhoneInput {
        label: "Phone",
        value: phone(),
        default_country: "GB",
        description: "We text a code to this number",
        on_change: move |e164: String| phone.set(e164),
    }
}

Masked

All but the last four masked (Oxyn plus).

We text a code to this number
Code
rsx! {
    PhoneInput {
        label: "Phone",
        value: phone(),
        description: "We text a code to this number",
        masked: true,
        on_change: move |e164: String| phone.set(e164),
    }
}

API reference

PhoneInput

PropTypeDefaultDescription
labelrequiredString—Label.
hide_labelboolDefault::default()Keep the label for screen readers only.
valueStringDefault::default()Starting number in E.164.
default_countryString"US"ISO code until someone picks one.
localeOption<String>Default::default()Oxyn plus: pick the country from this locale (`en-GB`).
countriesVec<String>Default::default()Limit the picker to these ISO codes.
preferredVec<String>vec!["US".to_string(), "CA".to_string(), "GB".to_string()]Pinned under Suggested.
descriptionOption<String>Default::default()Hint.
errorOption<String>Default::default()Replaces the built-in message.
validatebooltrueMessage after blur on the wrong length.
maskedboolDefault::default()Oxyn plus: mask all but the last four digits when not focused.
openboolDefault::default()Start with the picker open (review sheets).
requiredboolDefault::default()Required.
nameOption<String>Default::default()Form field name (hidden input with E.164).
disabledboolDefault::default()Disabled.
on_changeEventHandler<String>—Every edit: E.164.
on_country_changeEventHandler<String>—Country changed.

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
(in the number)Open the picker with a calling-code search
↓or↑ (country button)Open the picker
A letter (country button)Open the picker searching for it
↓or↑orPage DownorPage UpMove through countries
HomeorEndFirst / last country when the search is empty
EnterPick and return to the number
EscClose the picker

Accessibility

  • The search is a combobox with aria-activedescendant over a listbox grouped into Suggested and All countries.
  • The country button reads “Country, United States +1”; picks and pasted country changes are announced.
  • type=tel, autocomplete=tel; errors show after blur with role=alert.
From the spec

The country button reads "Country, United Kingdom +44" with aria-haspopup=listbox and aria-expanded. The search is a combobox with aria-activedescendant; the list is grouped. Picks, pasted country changes, result counts and validity are announced politely. Errors show after blur only, as role=alert.

Motion & interaction

The picker grows out of the flag button. On a country change the flag and code roll — down the list rolls up, up the list rolls down. Separators appear as you type; Backspace over a separator removes the digit before it.

Timing
TransitionDurationEasingReduced motion
Picker grow220 ms from top-leftease.out80 ms fade
Flag / code roll200 msease.outswap
Valid check220 ms popease.outinstant
Message in180 msease.outswap

Responsive behaviour

  • The list is as wide as the field up to 340 px.
  • inputmode=tel opens the phone keypad.
Edge cases (spec)

Trunk prefixes (0) are kept as typed but dropped in E.164. +1 resolves Canada by area code. Digits past the pattern are kept, never dropped. 15-digit cap (E.164). Pastes with letters keep the digits. Narrow screens: the list is as wide as the field, up to 340 px. inputmode=tel opens the keypad.

Notes for AI

  • Import PhoneInput from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: PhoneInputEl in oxyn_gpui.
  • Props to set first: label.
  • Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI