A phone input component with country code selection.

Parameters:
NameTypeDescription
propsobject

Component props

Properties
NameTypeDescription
countriesArray

Array of country codes.

customAttributesobject

Custom attributes for the component.

customClassesstring | Array | object

Custom classes for the component.

disabledboolean

Whether the input is disabled.

dropdownAttributesobject

Custom attributes for the dropdown.

dropdownClassesstring | Array | object

Custom classes for the dropdown.

helpTextAttributesobject

Custom attributes for the help text.

helpTextClassesstring | Array | object

Custom classes for the help text.

i18nobject

i18n object for the country dropdown component.

idstring

Optional id (auto-generated if not provided).

inputAttributesstring

Custom attributes for the input.

inputClassesstring | Array | object

Custom classes for the input.

internationalboolean

Whether the phone number is international format.

labelobject

Label text.

labelAttributesobject

Custom attributes for the label.

labelClassesstring | Array | object

Custom classes for the label.

languagestring

Language code for the country dropdown component.

onChangefunction

Change handler function, fires both on input and dropdown change. Receives { country, number, isValid }.

preferredCountriesArray

Array of preferred country codes.

requiredboolean

Whether the field is required.

requiredLabelAttributesobject

Custom attributes for the required label.

requiredLabelClassesstring | Array | object

Custom classes for the required label.

sizestring

Component size: 'r', 'l', or 'xl'.

spacingstring | number | Array | object

Component spacing.

usePlaceholderboolean

Whether to use a placeholder.

useValidationboolean

Whether to use validation for the phone input.

widthnumber

Width of the component in pixels.

refobject

Forwarded ref.

Since
  • 5.5.0
Returns:

Phone component

Type: 
JSX.Element
Example
import Phone from '@gravityforms/components/react/admin/modules/Phone';

return <Phone
    countries={ [ 'US', 'CA', 'GB', 'MX', 'DE', 'JP' ] }
    helpTextAttributes={ { content: 'The phone number you entered is not valid.' } }
    i18n={ { allCountries: 'All countries' } }
    id="contact-phone"
    international={ true }
    label="Phone Number"
    onChange={ ( value, event ) => {
        console.log( 'country: ', value.country );
        console.log( 'number: ', value.number );
        console.log( 'isValid: ', value.isValid );
        console.log( 'event: ', event );
    } }
    preferredCountries={ [ 'US', 'CA', 'GB' ] }
    required={ true }
    requiredLabelAttributes={ { content: '(Required)' } }
    size="xl"
    usePlaceholder={ true }
    useValidation={ true }
    width={ 500 }
/>;