PhoneInput

core package3.2.2

Note: All components shown on this site are supported by the Constellation design system. To learn how to configure Theme Cosmos, visit Pega Community.

PhoneInputs allow for users to enter and edit phone numbers, typically in a Form. There is masking support for phone numbers with a +1 country code (USA).

Usage

PhoneInputs will accept numbers only and can also render a Select menu for choosing country codes if the showCountryCode property is passed. The list of country codes that populates the Select menu is configurable via the callingCodesList prop.

The component also allows for standard Form Field structures such as being set required, disabled, or readOnly, as well as including a label, status, or info. If an onResolveSuggestion callback function is provided, and the status is set to pending, the user will be prompted to accept or deny whatever suggested value populates the PhoneInput.

If there is a label and the Field is not disabled, passing an object to the additionalInfo prop that includes a heading and content will provide the user with more useful information on the Field when they click on the associated information Icon.

Example

Phone input
Enter a phone number

Related components

Properties

NameDescriptionDefaultType
additionalInfoButton when clicked will show additional information on a field
{
  content: string | Element;
  heading: string;
}
callingCodesListChanges lists of countries calling codesstring[]
classNameAdditional CSS classes.string
defaultValueIf you wish to use an uncontrolled input, pass a defaultValue prop and a ref to access the input's native value prop or by other DOM ref means.string
disabledDisable the control. The browser defaults to false.boolean
idSets DOM id for the control and associates label element via 'for' attribute. If an id is not pass, a random id will be generated for any render.string
infoIt is recommended to pass a simple string to offer guidance. Text will be styled based on status prop.ReactNode
labelPass a string or a fragment with an Icon and string.ReactNode
labelHiddenVisually hides the label region.boolean
nameSets html name attribute for the underlying control. Useful for mapping to a data field.string
onBlur(value: string) => void
onChange(value: string) => void
onFocus(value: string) => void
onResolveSuggestion(accepted: boolean) => void
placeholderPlaceholder text. The browser defaults to an empty string.string
readOnlyMakes the input non editable and non clickable. The browser defaults to false.boolean
refRef for the wrapping element.Ref<HTMLInputElement>
requiredIndicate if the field is required. The browser defaults to false.boolean
showCountryCodeDisplay select with countries calling codesfalseboolean
statusSet visual state based on a validation state.
'error' |'pending' |'success' |'warning' 
valueCreates a controlled input and sets the value. Requires an onChange handler to update value. value + onChange is the recommended method per React team.string