Skip to main content

PhoneInput

The TkPhoneInput component allows users to input phone numbers with country selection and validation.

import { TkPhoneInput } from '@takeoff-ui/react'

Basic​

A simple TkPhoneInput display.

View Code
<TkPhoneInput 
label="Phone Input"
hint="Hint text"
placeholder="Placeholder text"
value={value}
onTkChange={(e) => setValue(e.detail)}
/>

Custom Country List​

You can provide a custom list of countries to the phone input. This allows you to control which countries are available for selection in the dropdown.

  countryList=[
{ label: 'Azerbaijan', id: 'AZ', dialCode: '+994', mask: '99 999 99 99' },
{ label: 'Bolivia', id: 'BO', dialCode: '+591', mask: '99999999' },
{ label: 'Brazil', id: 'BR', dialCode: '+55', mask: '(99) 99999-9999' },
{ label: 'Japan', id: 'JP', dialCode: '+81', mask: '99-9999-9999' },
{ label: 'Portugal', id: 'PT', dialCode: '+351', mask: '999 999 999' },
{ label: 'Turkey', id: 'TR', dialCode: '+90', mask: '(999) 999 9999' }
]
View Code
<TkPhoneInput 
label="Phone Input"
showAsterisk={true}
countryList={countryList}
defaultCountry='AZ'
value={value}
onTkChange={(e) => setValue(e.detail)}
/>

Size​

The "size" prop can be used with one of the sizes "small", "base", and "large". The default value is "base".

View Code
<TkPhoneInput
label="Small Input"
size="small"
value={value}
onTkChange={(e) => setValue(e.detail)}
/>
<TkPhoneInput
label="Base Input"
size="base"
value={value1}
onTkChange={(e) => setValue1(e.detail)}
/>
<TkPhoneInput
label="Large Input"
size="large"
value={value2}
onTkChange={(e) => setValue2(e.detail)}
/>

State​

This example illustrates the disabled, readonly, and invalid states of the phone input field. Each state demonstrates how the input behaves and visually changes in different interaction scenarios.

View Code
<TkPhoneInput
label="Error"
placeholder="Error"
invalid={true}
error="This field is required"
/>
<TkPhoneInput
label="Readonly"
placeholder="Readonly"
readonly
/>
<TkPhoneInput
label="Disabled"
placeholder="Disabled"
disabled
/>

API​

Props​

NameTypeDefaultDescription
ICountry[]nullThe list of countries to display in the dropdown. Can be provided as an array of Country objects or as a JSON string.
string'TR'The default country to select (ISO country code).
booleanfalseWhether the input is disabled. *
stringnullThis is the error message that will be displayed.
stringnullProvided a hint or additional information about the input.
booleanfalseIndicates whether the input is in an invalid state
stringnullThe label for the phone input.
stringnullPlaceholder text for the phone input.
booleanfalseIf true, the user cannot modify the value.
booleanfalseDisplays a red asterisk (*) next to the label for visual emphasis.
"base", "large", "small"'base'Sets size for the component.
anynullThe value of the phone input. This is a list of phone input data objects. It can be mutable to allow two-way binding.

Events​

NameDescription
tk-blurEmitted when the input loses focus.
tk-changeEmitted when the value has changed.
tk-focusEmitted when the input has focus.

Interfaces​

Interface for the output data emitted by the phone input

interface IPhoneInputValue {
/** The raw phone number without formatting */
rawValue: string;
/** The formatted phone number with mask applied */
maskedValue: string;
/** The selected country object */
country: ICountry;
}

Interface representing a country for phone number input

interface ICountry {
/** The display name of the country */
label: string;
/** The ISO country code */
id: string;
/** The international dialing code with + prefix */
dialCode: string;
/** The phone number mask pattern where 9 represents a digit */
mask: string;
}