DateField
Description
A date picker input field component that integrates with React Hook Form. Supports min/max date validation and provides a native date picker interface.
Import
import { DateField } from '@components/common/form/DateField';
Usage
import { Form } from '@components/common/form/Form';
import { DateField } from '@components/common/form/DateField';
function EventForm() {
return (
<Form action="/api/events">
<DateField
name="eventDate"
label="Event Date"
required
/>
</Form>
);
}
Props
| Name | Type | Default | Description |
|---|---|---|---|
| name | FieldPath<T> | - | Field name (required) |
| label | string | - | Label text displayed above the input |
| min | string | - | Minimum allowed date (YYYY-MM-DD format) |
| max | string | - | Maximum allowed date (YYYY-MM-DD format) |
| required | boolean | false | Makes the field required |
| error | string | - | Custom error message |
| helperText | string | - | Helper text shown in a tooltip |
| validation | RegisterOptions<T> | - | React Hook Form validation rules |
| wrapperClassName | string | - | CSS class for the wrapper div |
| ...props | InputHTMLAttributes | - | All standard HTML input attributes |
Example: With Min/Max Dates
import { Form } from '@components/common/form/Form';
import { DateField } from '@components/common/form/DateField';
function BookingForm() {
const today = new Date().toISOString().split('T')[0];
const maxDate = new Date();
maxDate.setFullYear(maxDate.getFullYear() + 1);
return (
<Form action="/api/bookings">
<DateField
name="checkIn"
label="Check-in Date"
min={today}
max={maxDate.toISOString().split('T')[0]}
required
helperText="Select a date within the next year"
/>
</Form>
);
}
Example: Birthday Field
import { Form } from '@components/common/form/Form';
import { DateField } from '@components/common/form/DateField';
function ProfileForm() {
const today = new Date().toISOString().split('T')[0];
const minDate = '1900-01-01';
return (
<Form action="/api/profile">
<DateField
name="birthdate"
label="Date of Birth"
min={minDate}
max={today}
required
/>
</Form>
);
}
Features
- Native Date Picker: Uses browser's native date picker interface
- Min/Max Validation: Built-in validation for date ranges
- Auto-cleanup: Automatically unregisters on unmount
- TypeScript Support: Full type safety with generics
Date Format
Values are in YYYY-MM-DD format (ISO 8601 date string).
Related Components
- Form - Parent form component
- DateTimeLocalField - Date and time picker
- TimeField - Time picker