Input Phone
- Needs review
- WCAG 2.2 evidence
- RTL
- Web · iOS · Android
Phone number field: a label, a field box with a country picker (flag, dial code, chevron) and a
number input, helper text and an inline error. Built on React Aria TextField (the number: type="tel", inputMode="tel",
autoComplete="tel-national") and Select (the country: a button with a listbox popup), reusing the Input field parts
and the Select list and options, so it looks and behaves like both. Accessibility: the label, helper and error are linked to the number (WCAG 1.3.1, 3.3.2); the box is a group named by the
label; the country button is named by countryLabel, the country name and the dial code ("Country Pakistan +92"), so the
country is always available as text even when only a flag is visible (1.1.1). Tab moves from the country button to the
number; Enter, Space, Arrow Down or Arrow Up open the list, typing a letter picks a country by name, Escape closes and
returns focus (2.1.1, 2.4.3). With isRequired / validate / native constraints the error appears on submit, focus moves to the
number and the error is read with it; it shows an icon and text, never colour alone (1.4.1, 3.3.1, 4.1.3). Paste and
autofill are never blocked; a pasted international number selects its country (3.3.7, 3.3.8). The dial code and the
number form one phone number that reads left to right, so the box never mirrors in right-to-left layouts (rule G4); the
label, helper, error and the list do. Consumer duties: the country list (names translated, dial codes correct), label, helper and error wording, validation
rules per country, the autoComplete token (1.3.5) and why a field is disabled.
import { InputPhone } from "@nexera-ui/react";- 10
- examples
- 42
- props
- 10
- live controls
- 3
- platforms
- 18
- WCAG criteria
- 3
- blocks use it
Try every prop. Copy the code.
Change the props and the code updates. Check light and dark, LTR and RTL, and phone width.
import { InputPhone } from "@nexera-ui/react";
<InputPhone />Examples 9
The same examples as Storybook, rendered live. Open Code to copy one.
States
Semantic states: filled, isDisabled, isInvalid + errorMessage and read-only.
import { type ReactNode } from "react";
import { InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const countries: readonly InputPhoneCountry[] = [
{ code: "PK", name: "Pakistan", dialCode: "+92", flag: flags["PK"] },
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", flag: flags["AE"] },
{ code: "BD", name: "Bangladesh", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "Germany", dialCode: "+49", flag: flags["DE"] },
{ code: "FR", name: "France", dialCode: "+33", flag: flags["FR"] },
{ code: "IE", name: "Ireland", dialCode: "+353", flag: flags["IE"] },
{ code: "NG", name: "Nigeria", dialCode: "+234", flag: flags["NG"] },
{ code: "NL", name: "Netherlands", dialCode: "+31", flag: flags["NL"] },
];
export function States() {
return (
<div className="flex flex-col gap-6">
<InputPhone
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
description="Leave approvals are sent by SMS."
label="Filled"
defaultValue="300 1234567"
/>
<InputPhone
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
description="Leave approvals are sent by SMS."
label="Disabled"
isDisabled
/>
<InputPhone
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
description="Leave approvals are sent by SMS."
label="Error"
defaultValue="300 12"
isInvalid
errorMessage="Enter a valid mobile number for Pakistan."
/>
<InputPhone
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
description="Leave approvals are sent by SMS."
label="Read-only"
defaultValue="300 1234567"
isReadOnly
/>
</div>
);
}
Country list open
The country list is open: flag, name and dial code per country; the selected one has a check mark.
import { type ReactNode } from "react";
import { InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const countries: readonly InputPhoneCountry[] = [
{ code: "PK", name: "Pakistan", dialCode: "+92", flag: flags["PK"] },
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", flag: flags["AE"] },
{ code: "BD", name: "Bangladesh", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "Germany", dialCode: "+49", flag: flags["DE"] },
{ code: "FR", name: "France", dialCode: "+33", flag: flags["FR"] },
{ code: "IE", name: "Ireland", dialCode: "+353", flag: flags["IE"] },
{ code: "NG", name: "Nigeria", dialCode: "+234", flag: flags["NG"] },
{ code: "NL", name: "Netherlands", dialCode: "+31", flag: flags["NL"] },
];
export function CountryListOpen() {
return (
<div className="min-h-[26rem]">
<InputPhone
label="Mobile number"
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
description="Leave approvals are sent by SMS."
/>
</div>
);
}
Validation on submit
Validation on submit: the error appears under the field with an icon, focus moves to the number and the error is read with it. validate receives the national number with Latin digits. Paste is never blocked: pasting "+971 50 123 4567" selects the United Arab Emirates and keeps "50 123 4567".
import { type ReactNode } from "react";
import { Form } from "react-aria-components";
import { Button, InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const countries: readonly InputPhoneCountry[] = [
{ code: "PK", name: "Pakistan", dialCode: "+92", flag: flags["PK"] },
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", flag: flags["AE"] },
{ code: "BD", name: "Bangladesh", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "Germany", dialCode: "+49", flag: flags["DE"] },
{ code: "FR", name: "France", dialCode: "+33", flag: flags["FR"] },
{ code: "IE", name: "Ireland", dialCode: "+353", flag: flags["IE"] },
{ code: "NG", name: "Nigeria", dialCode: "+234", flag: flags["NG"] },
{ code: "NL", name: "Netherlands", dialCode: "+31", flag: flags["NL"] },
];
export function ValidationOnSubmit() {
return (
<Form
className="flex flex-col gap-6"
onSubmit={(event) => {
event.preventDefault();
}}
>
<InputPhone
label="Mobile number"
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
description="Leave approvals are sent by SMS."
name="mobile"
countryFieldName="mobileCountry"
isRequired
validate={(value) =>
value === "" || value.replace(/\D/g, "").length >= 9
? null
: "Enter the full mobile number, like 300 1234567."
}
errorMessage={(validation) =>
validation.validationDetails.valueMissing
? "Enter a mobile number."
: validation.validationErrors.join(" ")
}
/>
<Button type="submit" className="self-start">
Save
</Button>
</Form>
);
}
Platforms
Input Mobile pattern on iOS (50 pt) and Android (52 dp): radius 12, Body/Large, 20 px chevron. Web is 40 px.
import { type ReactNode } from "react";
import { InputPhone } from "@nexera-ui/react";
const platforms = ["web", "ios", "android"] as const;
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const countries: readonly InputPhoneCountry[] = [
{ code: "PK", name: "Pakistan", dialCode: "+92", flag: flags["PK"] },
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", flag: flags["AE"] },
{ code: "BD", name: "Bangladesh", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "Germany", dialCode: "+49", flag: flags["DE"] },
{ code: "FR", name: "France", dialCode: "+33", flag: flags["FR"] },
{ code: "IE", name: "Ireland", dialCode: "+353", flag: flags["IE"] },
{ code: "NG", name: "Nigeria", dialCode: "+234", flag: flags["NG"] },
{ code: "NL", name: "Netherlands", dialCode: "+31", flag: flags["NL"] },
];
export function Platforms() {
return (
<div className="flex flex-col gap-6">
{platforms.map((platform) => (
<InputPhone
key={platform}
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
description="Leave approvals are sent by SMS."
platform={platform}
label={`Mobile number (${platform})`}
/>
))}
</div>
);
}
Without flags
Flags are optional: the button then shows the dial code, and the list shows names and dial codes.
import { type ReactNode } from "react";
import { InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const countries: readonly InputPhoneCountry[] = [
{ code: "PK", name: "Pakistan", dialCode: "+92", flag: flags["PK"] },
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", flag: flags["AE"] },
{ code: "BD", name: "Bangladesh", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "Germany", dialCode: "+49", flag: flags["DE"] },
{ code: "FR", name: "France", dialCode: "+33", flag: flags["FR"] },
{ code: "IE", name: "Ireland", dialCode: "+353", flag: flags["IE"] },
{ code: "NG", name: "Nigeria", dialCode: "+234", flag: flags["NG"] },
{ code: "NL", name: "Netherlands", dialCode: "+31", flag: flags["NL"] },
];
<InputPhone
label="Mobile number"
countries={countries.map(({ code, name, dialCode }) => ({ code, name, dialCode }))}
defaultCountry="AE"
placeholder="50 123 4567"
description="Leave approvals are sent by SMS."
/>;
Long label
Long labels and helper texts wrap; the number scrolls inside the box.
import { type ReactNode } from "react";
import { InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const countries: readonly InputPhoneCountry[] = [
{ code: "PK", name: "Pakistan", dialCode: "+92", flag: flags["PK"] },
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", flag: flags["AE"] },
{ code: "BD", name: "Bangladesh", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "Germany", dialCode: "+49", flag: flags["DE"] },
{ code: "FR", name: "France", dialCode: "+33", flag: flags["FR"] },
{ code: "IE", name: "Ireland", dialCode: "+353", flag: flags["IE"] },
{ code: "NG", name: "Nigeria", dialCode: "+234", flag: flags["NG"] },
{ code: "NL", name: "Netherlands", dialCode: "+31", flag: flags["NL"] },
];
export function LongLabel() {
return (
<div className="max-w-[14rem]">
<InputPhone
countries={countries}
defaultCountry="PK"
placeholder="300 1234567"
label="Mobile number for leave approvals, payslip alerts and emergency contact"
description="We send a text message with a code each time an approval needs your attention."
defaultValue="300 1234567 ext. 4410"
/>
</div>
);
}
Right to left
Right-to-left: the label, helper text and country list mirror; the dial code and the number form one phone number that reads left to right, so the field box keeps its order.
import { type ReactNode } from "react";
import { InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const arabicCountries: readonly InputPhoneCountry[] = [
{ code: "AE", name: "الإمارات العربية المتحدة", dialCode: "+971", flag: flags["AE"] },
{ code: "PK", name: "باكستان", dialCode: "+92", flag: flags["PK"] },
{ code: "BD", name: "بنغلاديش", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "ألمانيا", dialCode: "+49", flag: flags["DE"] },
];
export function RightToLeft() {
return (
<div className="flex flex-col gap-6">
<InputPhone
label="رقم الجوال"
countryLabel="الدولة"
countries={arabicCountries}
placeholder="50 123 4567"
description="نرسل موافقات الإجازات برسالة نصية."
/>
<InputPhone
label="هاتف العمل"
countryLabel="الدولة"
countries={arabicCountries}
defaultCountry="PK"
defaultValue="300 12"
isInvalid
errorMessage="أدخل رقم جوال صالحًا."
/>
</div>
);
}
Locale digits
digits="locale": under an ar-EG locale the number and dial codes use Arabic-Indic digits. The value, validate and the submitted form value keep Latin digits. Without it the field shows Latin digits in every locale.
import { type ReactNode } from "react";
import { I18nProvider } from "react-aria-components";
import { InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const arabicCountries: readonly InputPhoneCountry[] = [
{ code: "AE", name: "الإمارات العربية المتحدة", dialCode: "+971", flag: flags["AE"] },
{ code: "PK", name: "باكستان", dialCode: "+92", flag: flags["PK"] },
{ code: "BD", name: "بنغلاديش", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "ألمانيا", dialCode: "+49", flag: flags["DE"] },
];
export function LocaleDigits() {
return (
<I18nProvider locale="ar-EG">
<InputPhone
label="رقم الجوال"
countryLabel="الدولة"
countries={arabicCountries}
digits="locale"
defaultValue="50 123 4567"
description="تظهر الأرقام بالأرقام العربية."
/>
</I18nProvider>
);
}
Contact verification
import { useState, type ReactNode } from "react";
import { Button, Card, Input, InputPhone } from "@nexera-ui/react";
function StripesFlag({
colors,
direction,
}: {
colors: readonly string[];
direction: "horizontal" | "vertical";
}) {
const size = 1 / colors.length;
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
{colors.map((fill, index) =>
direction === "horizontal" ? (
<rect key={index} x="0" y={index * 2 * size} width="3" height={2 * size} fill={fill} />
) : (
<rect key={index} x={index * 3 * size} y="0" width={3 * size} height="2" fill={fill} />
),
)}
</svg>
);
}
function FlagPakistan() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill="#01411c" />
<rect width="0.75" height="2" fill="#ffffff" />
<circle cx="1.95" cy="1" r="0.5" fill="#ffffff" />
<circle cx="2.08" cy="0.9" r="0.43" fill="#01411c" />
<circle cx="2.2" cy="0.82" r="0.1" fill="#ffffff" />
</svg>
);
}
function FlagEmirates() {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="0.667" fill="#00732f" />
<rect y="0.667" width="3" height="0.667" fill="#ffffff" />
<rect y="1.333" width="3" height="0.667" fill="#000000" />
<rect width="0.75" height="2" fill="#ff0000" />
</svg>
);
}
function FlagDisc({ field, disc }: { field: string; disc: string }) {
return (
<svg viewBox="0 0 3 2" preserveAspectRatio="none" aria-hidden="true">
<rect width="3" height="2" fill={field} />
<circle cx="1.35" cy="1" r="0.6" fill={disc} />
</svg>
);
}
const flags: Record<string, ReactNode> = {
PK: <FlagPakistan />,
AE: <FlagEmirates />,
BD: <FlagDisc field="#006a4e" disc="#f42a41" />,
DE: <StripesFlag direction="horizontal" colors={["#000000", "#dd0000", "#ffce00"]} />,
FR: <StripesFlag direction="vertical" colors={["#0055a4", "#ffffff", "#ef4135"]} />,
IE: <StripesFlag direction="vertical" colors={["#169b62", "#ffffff", "#ff883e"]} />,
NG: <StripesFlag direction="vertical" colors={["#008751", "#ffffff", "#008751"]} />,
NL: <StripesFlag direction="horizontal" colors={["#ae1c28", "#ffffff", "#21468b"]} />,
};
const countries: readonly InputPhoneCountry[] = [
{ code: "PK", name: "Pakistan", dialCode: "+92", flag: flags["PK"] },
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", flag: flags["AE"] },
{ code: "BD", name: "Bangladesh", dialCode: "+880", flag: flags["BD"] },
{ code: "DE", name: "Germany", dialCode: "+49", flag: flags["DE"] },
{ code: "FR", name: "France", dialCode: "+33", flag: flags["FR"] },
{ code: "IE", name: "Ireland", dialCode: "+353", flag: flags["IE"] },
{ code: "NG", name: "Nigeria", dialCode: "+234", flag: flags["NG"] },
{ code: "NL", name: "Netherlands", dialCode: "+31", flag: flags["NL"] },
];
function ContactVerificationDemo() {
const [number, setNumber] = useState("");
const [country, setCountry] = useState("PK");
const [step, setStep] = useState("contact");
const [code, setCode] = useState("");
const [error, setError] = useState("");
return (
<div className="w-[24rem] max-w-full">
<Card
title="Keep your account connected"
body="Choose a country and verify your contact number. This is a local demo; no SMS is sent."
>
<div className="mt-4 flex flex-col gap-4">
{step === "contact" ? (
<>
<InputPhone
label="Contact number"
countries={countries}
country={country}
onCountryChange={setCountry}
value={number}
onChange={(value) => {
setNumber(value);
setError("");
}}
placeholder="300 1234567"
isInvalid={Boolean(error)}
errorMessage={error}
/>
<Button
onPress={() => {
if (number.replace(/\D/g, "").length < 9) setError("Enter at least nine digits.");
else setStep("verify");
}}
>
Continue to verification
</Button>
</>
) : step === "verify" ? (
<>
<p className="m-0 text-body-default">
Verifying {countries.find((entry) => entry.code === country)?.dialCode} {number}
</p>
<Input
label="Verification code"
description="Use 123456 for this demo."
inputMode="numeric"
maxLength={6}
value={code}
onChange={(value) => {
setCode(value);
setError("");
}}
isInvalid={Boolean(error)}
errorMessage={error}
/>
<Button
onPress={() => {
if (code === "123456") setStep("done");
else setError("Use the demo code 123456.");
}}
>
Verify contact
</Button>
<Button
variant="secondary"
onPress={() => {
setStep("contact");
setError("");
}}
>
Edit number
</Button>
</>
) : (
<>
<p role="status" className="m-0 text-body-default">
Your contact is verified in this demo.
</p>
<Button
variant="secondary"
onPress={() => {
setStep("contact");
setCode("");
}}
>
Start again
</Button>
</>
)}
</div>
</Card>
</div>
);
}
const ContactVerification = { render: () => <ContactVerificationDemo /> };
Props 42
Press "Try it" on a card to load that prop into the playground.
42 props shown
countries*Nexerareadonly InputPhoneCountry[]The countries to pick from (consumer data: the library ships no country list and no flag assets). Each entry has a
unique code, a translated name, a dialCode and an optional decorative flag. Put the most likely countries
first or pass defaultCountry. Figma Country flag and Dial code are taken from the selected entry.
countryNexerastringCode of the selected country (controlled). Pair it with onCountryChange.
defaultCountryNexerastringCode of the country selected on first render (uncontrolled).
onCountryChangeNexera(code: string) => voidCalled with the new country code when the user picks a country, or when a pasted international number selects one.
countryLabelNexerastringFirst part of the country button's accessible name, followed by the country name and dial code ("Country Pakistan +92"); also the name of the country list. Translate it for your locale.
countryFieldNameNexerastringForm field name under which the selected country code is submitted (the number uses name).
isOpenNexerabooleanWhether the country list is open (controlled). Use with onOpenChange.
defaultOpenNexerabooleanWhether the country list is open on first render (uncontrolled).
onOpenChangeNexera(isOpen: boolean) => voidCalled when the country list opens or closes.
valueNexerastringThe national number, without the dial code, always with Latin
digits. Pair it with onChange.
defaultValueNexerastringThe national number on first render (uncontrolled).
onChangeNexera(value: string) => voidCalled with the national number as the user edits it. Digits typed in another numbering system (٣٠٠, ۳۰۰,...)
arrive as Latin digits. Pasting or autofilling an international number (+92 300 1234567) selects the country whose
dial code starts it and keeps only the national part.
descriptionNexeraReactNodeHelper text under the field, for example the expected format. Linked to the
number with aria-describedby. Replaced by the error message while the field is invalid, as in the Figma Error state.
errorMessageNexeraReactNode | ((validation: ValidationResult) => ReactNode)Error text under the field, shown with an icon while the field is invalid (isInvalid, or a
failed isRequired / validate / native constraint after submit) and linked with aria-describedby. Say what is wrong
and how to fix it ("Enter a valid mobile number for Pakistan"). A function receives React Aria's validation result.
placeholderNexerastringExample number shown while the field is empty. Never the only label.
digitsNexera"latin" | "locale"Digits shown in the number and the dial codes: "latin" (0-9) whatever the locale, or "locale" for the numbering
system of the I18nProvider / NexeraProvider locale (for example ٠-٩ for ar-EG). The value, onChange,
validate and the submitted form value always use Latin digits.
autoCompleteNexerastringAutofill token of the number (WCAG 1.3.5). The country is picked separately, so the default asks for the national
number; use "tel" to let the browser fill the full international number (its dial code then selects the country).
inputModeNexera"none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search"Virtual keyboard of the number.
platformNexera"web" | "ios" | "android"Platform look: 50 pt / 52 dp box with Body/Large text on
iOS and Android. Defaults to the NexeraProvider platform.
inputRefNexeraRef<HTMLInputElement>Ref to the native number <input> (the root ref points to the field wrapper).
classNameNexerastringExtra classes for the root, merged last so they win over the defaults.
styleNexeraCSSPropertiesInline style of the root.
labelNexeraFieldLabelContentVisible label, linked to the control by React Aria (WCAG 1.3.1, 3.3.2). Short noun, for example "Work email". Wraps instead of truncating. A placeholder is never a substitute for it. Not set: the field has no visible label. Not set: the field has no visible label of its own.
aria-labelNexerastringAccessible name when it must differ from the visible label. Prefer the visible label (WCAG 2.5.3).
Accessible name. Required when there is no visible label; translate it.
Accessible name. Optional when aria-labelledby is set.
aria-labelledbyNexerastringId(s) of element(s) that name the field; wins over the visible label.
Id(s) of element(s) that name the field; wins over aria-label.
Id(s) of visible element(s) that name the field.
validationBehaviorReact Aria"native" | "aria"Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
enterKeyHintReact Aria"search" | "enter" | "done" | "go" | "next" | "previous" | "send"An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint).
isDisabledReact AriabooleanWhether the input is disabled.
isReadOnlyReact AriabooleanWhether the input can be selected but not changed by the user.
isRequiredReact AriabooleanWhether user input is required on the input before form submission.
isInvalidReact AriabooleanWhether the value is invalid.
validateReact Aria(value: string) => true | ValidationError | nullA function that returns an error message if a given value is invalid.
Validation errors are displayed to the user when the form is submitted
if validationBehavior="native". For realtime validation, use the isInvalid
prop instead.
autoFocusReact AriabooleanWhether the element should receive focus on render.
aria-describedbyReact AriastringIdentifies the element (or elements) that describes the object.
idReact AriastringThe element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
maxLengthReact ArianumberThe maximum number of characters supported by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength).
minLengthReact ArianumberThe minimum number of characters required by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength).
patternReact AriastringRegex pattern that the value of the input must match to be valid. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefpattern).
autoCorrectReact AriastringAn attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete).
spellCheckReact AriastringAn enumerated attribute that defines whether the element may be checked for spelling errors. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck).
nameReact AriastringThe name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname).
formReact AriastringThe <form> element to associate the input with.
The value of this attribute must be the id of a <form> in the same document.
See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).
* Required. React Aria props shown are the ones most apps use; the component accepts the rest of its React Aria props too.
Accessible by default.
Built on React Aria, and covered by the WCAG 2.2 evidence generated on every build.
WCAG 2.2 evidence
12 direct · 6 supporting- 1.1.1Non-text ContentLevel A · tested directly
- 1.3.1Info and RelationshipsLevel A · tested directly
- 1.3.2Meaningful SequenceLevel A · supporting test
- 1.3.5Identify Input PurposeLevel AA · tested directly
- 1.4.1Use of ColorLevel A · tested directly
- 1.4.10ReflowLevel AA · supporting test
- 1.4.11Non-text ContrastLevel AA · supporting test
- 1.4.12Text SpacingLevel AA · supporting test
- 2.1.1KeyboardLevel A · tested directly
- 2.4.3Focus OrderLevel A · tested directly
- 2.4.7Focus VisibleLevel AA · supporting test
- 2.5.8Target Size (Minimum)Level AA · supporting test
- 3.3.1Error IdentificationLevel A · tested directly
- 3.3.2Labels or InstructionsLevel A · tested directly
- 3.3.3Error SuggestionLevel AA · tested directly
- 3.3.7Redundant EntryLevel A · tested directly
- 3.3.8Accessible Authentication (Minimum)Level AA · tested directly
- 4.1.2Name, Role, ValueLevel A · tested directly
Fits any width.
Nexera components respond to the space they are given. Drag the corner of the frame, or pick a width.
Styling hooks
Pass className to add Tailwind classes (merged last). State is exposed as data attributes, so you can style it with variants like data-pressed:.
data-disableddata-focus-withindata-hovereddata-invaliddata-opendata-pressed
<InputPhone className="data-disabled:opacity-90 shadow-sm" />Used in blocks
Related components
- CalendarDayOne day of a {@link CalendarMonth } grid, built on React Aria `CalendarCell`: a `gridcell` whose button is named by the full, localised date ("Wednesday, October 14, 2026"), with `aria-selected`, `aria-disabled` and the "today" and range descriptions read by screen readers (WCAG 1.3.1, 4.1.2).
- CalendarMonthA month calendar for picking a date or a date range: header with previous / next buttons and the localised month name, weekday row, and six weeks of `CalendarDay`s.
- CheckboxThe bare 18 px checkbox: one independent yes/no choice applied on submit, or a row selector in a table, list or tree.
- CheckboxCardA large checkbox option with an icon, a title and a description, for a few options that need explanation (notification channels, benefits).
- CheckboxFieldA checkbox with a label and optional helper text: the box (the same element as `Checkbox`) followed by the label and description, applied on submit.
- ColorInputA hex colour field with a swatch and a picker popover.
- ColorPickerPicks a colour.
- ColorTokenCardDocumentation card for one colour token: a 96 px colour sample with an "Aa" text sample, then the name, token path, hex value and contrast note as text.