Skip to main content

TelField

Description

A telephone number input field component that integrates with React Hook Form. Uses the HTML tel input type for better mobile keyboard support.

Import

import { TelField } from '@components/common/form/TelField';

Usage

import { Form } from '@components/common/form/Form';
import { TelField } from '@components/common/form/TelField';

function ContactForm() {
return (
<Form action="/api/contact">
<TelField
name="phone"
label="Phone Number"
required
/>
</Form>
);
}

Props

NameTypeDefaultDescription
nameFieldPath<T>-Field name (required)
labelstring-Label text displayed above the input
requiredbooleanfalseMakes the field required
errorstring-Custom error message
helperTextstring-Helper text shown in a tooltip
validationRegisterOptions<T>-React Hook Form validation rules
prefixIconReact.ReactNode-Icon displayed on the left inside the input
suffixIconReact.ReactNode-Icon displayed on the right inside the input
wrapperClassNamestring-CSS class for the wrapper div
...propsInputHTMLAttributes-All standard HTML input attributes

Example: With Validation

import { Form } from '@components/common/form/Form';
import { TelField } from '@components/common/form/TelField';

function PhoneForm() {
return (
<Form action="/api/phone">
<TelField
name="phone"
label="Phone Number"
placeholder="+1 (555) 123-4567"
required
validation={{
pattern: {
value: /^[\d\s\-\+\(\)]+$/,
message: 'Please enter a valid phone number'
}
}}
/>
</Form>
);
}

Example: With Icon

import { Form } from '@components/common/form/Form';
import { TelField } from '@components/common/form/TelField';
import { Phone } from 'lucide-react';

function EmergencyForm() {
return (
<Form action="/api/emergency">
<TelField
name="emergencyContact"
label="Emergency Contact"
placeholder="Enter phone number"
required
prefixIcon={<Phone size={16} />}
/>
</Form>
);
}

Features

  • Mobile Optimized: Uses tel input type for numeric keyboard on mobile devices
  • Icon Support: Add prefix or suffix icons
  • Flexible Format: No built-in format restrictions, add your own validation pattern
  • TypeScript Support: Full type safety with generics