Skip to main content

PhoneInput API

PhoneInput is a highly customizable phone input component.

Usage Example

Import component

import { PhoneInput } from 'react-international-phone';

Use by providing the defaultCountry, value and onChange callback.

<PhoneInput
defaultCountry="ua"
value={phone}
onChange={(phone) => setPhone(phone)}
/>

Output:

Properties

PropTypeDescriptionDefault value
defaultCountryCountryIso2Default country value (iso2)."us"
valuestringPhone value.""
countriesCountryData[]An array of available countries to select (and guess)defaultCountries
hideDropdownbooleanHide the dropdown icon. Make country selection not accessible.false
placeholderstringInput's placeholderundefined
disabledbooleanDisable phone input and country selector.false
prefixstringPrefix for phone value."+"
defaultMaskstringThis mask will apply on countries that does not have specified mask."............" (12 chars)
charAfterDialCodestringChar that renders after country dial code.
historySaveDebounceMSnumberSave value to history if there were not any changes in provided milliseconds timeslot.
Undo/redo (ctrl+z/ctrl+shift+z) works only with values that are saved in history
200
disableCountryGuessbooleanDisable country guess on value change.
- onCountryGuess callback would not be called.
false
disableDialCodePrefillbooleanDisable dial code prefill on initialization.
Dial code prefill works only when "empty" phone value have been provided.
false
forceDialCodebooleanAlways display the dial code.
Dial code can't be removed/changed by keyboard events, but it can be changed by pasting another country phone value.
false
disableDialCodeAndPrefixbooleanPhone value will not include passed dialCode and prefix if set to true.
- disableCountryGuess value will be ignored and set to true.
- forceDialCode value will be ignored and set to false.
false
showDisabledDialCodeAndPrefixbooleanShow prefix and dial code between country selector and phone input.
- Works only when disableDialCodeAndPrefix is true
false
inputPropsInputHTMLAttributesDefault input component propsundefined

Events

EventTypeDescription
onChange(phone: string, country: CountryIso2) => voidCallback that calls on phone change

Input events like onFocus and onBlur can be passed to the inputProps

Style properties

PropTypeDescription
styleCSSPropertiesCustom styles for PhoneInput container
classNamestringCustom className for PhoneInput container
inputStyleCSSPropertiesCustom styles for input field
inputClassNamestringCustom className for input field
countrySelectorStylePropsCountrySelectorStylePropsStyle properties for country selector
dialCodePreviewStylePropsDialCodePreviewStylePropsStyle properties for dial code preview

CSS variables

VariableDefault value
--react-international-phone-height36px
--react-international-phone-background-colorwhite
--react-international-phone-text-color#222
--react-international-phone-font-size13px
--react-international-phone-border-radius4px
--react-international-phone-border-colorgainsboro
--react-international-phone-disabled-background-colorwhitesmoke
--react-international-phone-disabled-text-color#666