Components
Phone input
A phone number and its country in one field.
'use client'
import { useState } from 'react'
import { PhoneInput } from '@dex/shared/components/phone-input'
export function PhoneInputDefault() {
const [phone, setPhone] = useState('')
return (
<div className="w-full max-w-sm">
<PhoneInput
aria-label="Phone number"
defaultCountry="GB"
placeholder="020 7946 0000"
value={phone}
onChange={setPhone}
/>
</div>
)
}
The hiring team may call you to arrange an interview.
'use client'
import { useState } from 'react'
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { PhoneInput } from '@dex/shared/components/phone-input'
export function PhoneInputInAField() {
const [phone, setPhone] = useState('+442079460123')
return (
<Field className="max-w-sm">
<FieldLabel>Phone number</FieldLabel>
<FieldControl>
<PhoneInput
defaultCountry="GB"
addInternationalOption={false}
initialValueFormat="national"
placeholder="020 7946 0000"
value={phone}
onChange={setPhone}
/>
</FieldControl>
<FieldMessage description="The hiring team may call you to arrange an interview." />
</Field>
)
}
Enter a phone number like 020 7946 0000.
'use client'
import { useState } from 'react'
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { PhoneInput } from '@dex/shared/components/phone-input'
export function PhoneInputInvalid() {
const [phone, setPhone] = useState('+4420794601')
return (
<Field invalid className="max-w-sm">
<FieldLabel>Phone number</FieldLabel>
<FieldControl>
<PhoneInput
defaultCountry="GB"
addInternationalOption={false}
initialValueFormat="national"
placeholder="020 7946 0000"
value={phone}
onChange={setPhone}
/>
</FieldControl>
<FieldMessage error="Enter a phone number like 020 7946 0000." />
</Field>
)
}
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import { PhoneInput } from '@dex/shared/components/phone-input'
export function PhoneInputDisabled() {
return (
<Field disabled className="max-w-sm">
<FieldLabel>Phone number</FieldLabel>
<FieldControl>
<PhoneInput
defaultCountry="GB"
initialValueFormat="national"
value="+442079460123"
disabled
/>
</FieldControl>
</Field>
)
}
From your Dex profile.
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { PhoneInput } from '@dex/shared/components/phone-input'
export function PhoneInputReadOnly() {
return (
<Field className="max-w-sm">
<FieldLabel>Phone number</FieldLabel>
<FieldControl>
<PhoneInput
defaultCountry="GB"
initialValueFormat="national"
value="+442079460123"
readOnly
/>
</FieldControl>
<FieldMessage description="From your Dex profile." />
</Field>
)
}
- The value is the full international number, such as
+442079460123, whatever the field shows. An empty field gives an empty string. - Set
defaultCountryto the country most people will be in, andaddInternationalOption={false}so the field always has a country. - Set
initialValueFormat="national"so a number filled in for the person reads 020 7946 0123, not +44 20 7946 0123. The flag already shows the country. - The country list opens with its search first, since most people type their country rather than scroll. Below 640px it opens in a bottom sheet, like the combobox.
- Give a read-only phone input helper text saying where the number came from.