PhoneInput
International phone number input with country selector
Source
LLM docs
Docs
Package
Usage
PhoneInput provides an international phone number input with country selector
and formatting masks.
Input features
PhoneInput component supports Input and Input.Wrapper component features and all input element props. The PhoneInput documentation does not include all features supported by the component – see the Input documentation to learn about all available features.
Input description
Loading state
Set loading prop to display a loading indicator in the input:
Controlled
Use value and onChange props to control the input value. The onChange callback
receives the raw value and a details object containing the formatted value and country data.
Raw value: +1 Formatted: Country: –
Preferred countries
Use preferredCountries prop to pin countries to the top of the dropdown.
Filter countries
Use onlyCountries to show only specific countries or excludeCountries to hide specific countries.
Custom flags
Use renderFlag prop to render custom flag elements, for example emoji flags.
The function receives country data and should return a React node.
Searchable
Country dropdown search is enabled by default. Set searchable={false} to disable it.
Country auto-detection
Set withCountryAutoDetect to automatically detect and switch the country when the user
types a dial code. For example, typing +44 will switch to United Kingdom.
Without the prop, the country still changes when a number starting with + and another dial code is typed or pasted.
Area codes, for example +1 204 for Canada, are detected only with the prop:
Localization
Use renderCountryOption to customize how countries are displayed in the dropdown.
This can be used to translate country names to a different language.
getCountryLabel returns the translated name of a country. It is used as the
country button label for screen readers and in the dropdown search, so users
can search by translated names. searchPlaceholder and selectCountryLabel
translate the search input placeholder and the button label shown before a
country is selected:
Dropdown position
Use within Popover
To use PhoneInput within Popover or other overlay, set comboboxProps={{ withinPortal: false }}.
Pressing Escape while the country list is open closes both the list and the Popover.
Set closeOnEscape={false} on the Popover to keep it open. The country list still closes on Escape:
Disabled state
Read only
Error state
Invalid phone number
Success state
Looks good!
Styles API
PhoneInput supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Get element ref
Accessibility
If PhoneInput is used without the label prop, it will not be announced properly by screen readers:
Set aria-label to make the input accessible. In this case the label will not be visible, but screen readers will announce it:
If the label prop is set, the input will be accessible and it is not required to set aria-label: