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-inputrsx! {
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.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add phone-inputuse 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
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.
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.
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.
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).
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
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | String | — | Label. |
hide_label | bool | Default::default() | Keep the label for screen readers only. |
value | String | Default::default() | Starting number in E.164. |
default_country | String | "US" | ISO code until someone picks one. |
locale | Option<String> | Default::default() | Oxyn plus: pick the country from this locale (`en-GB`). |
countries | Vec<String> | Default::default() | Limit the picker to these ISO codes. |
preferred | Vec<String> | vec!["US".to_string(), "CA".to_string(), "GB".to_string()] | Pinned under Suggested. |
description | Option<String> | Default::default() | Hint. |
error | Option<String> | Default::default() | Replaces the built-in message. |
validate | bool | true | Message after blur on the wrong length. |
masked | bool | Default::default() | Oxyn plus: mask all but the last four digits when not focused. |
open | bool | Default::default() | Start with the picker open (review sheets). |
required | bool | Default::default() | Required. |
name | Option<String> | Default::default() | Form field name (hidden input with E.164). |
disabled | bool | Default::default() | Disabled. |
on_change | EventHandler<String> | — | Every edit: E.164. |
on_country_change | EventHandler<String> | — | Country changed. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| (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 Up | Move through countries |
| HomeorEnd | First / last country when the search is empty |
| Enter | Pick and return to the number |
| Esc | Close 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
| Transition | Duration | Easing | Reduced motion |
|---|---|---|---|
| Picker grow | 220 ms from top-left | ease.out | 80 ms fade |
| Flag / code roll | 200 ms | ease.out | swap |
| Valid check | 220 ms pop | ease.out | instant |
| Message in | 180 ms | ease.out | swap |
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
PhoneInputfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
PhoneInputElinoxyn_gpui. - Props to set first:
label. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.