Skip to content

DatePicker

A date picker component that displays a text field which opens a Material 3 date picker dialog when tapped.

import { DatePicker } from '@mgcrea/react-native-jetpack-compose';
const [date, setDate] = useState<Date | null>(null);
<DatePicker
label="Select Date"
value={date}
onConfirm={setDate}
/>
PropTypeDefaultDescription
valueDate | number | string | nullnullSelected date
initialDisplayedMonthDate | number | string-Initially displayed month
minDateDate | number | string-Minimum selectable date
maxDateDate | number | string-Maximum selectable date
yearRangeYearRange-Year range for year selector
initialDisplayMode'picker' | 'input''picker'Initial display mode
showModeTogglebooleantrueShow mode toggle button
confirmLabelstring'OK'Confirm button text
cancelLabelstring'Cancel'Cancel button text
titlestring-Dialog title
labelstring-Text field label
placeholderstring-Text field placeholder
disabledbooleanfalseDisable the picker
styleViewStyle-Container style
EventTypeDescription
onConfirm(date: Date | null) => voidUser pressed OK
onCancel() => voidUser pressed Cancel
onChange(date: Date | null) => voidDate changed (before confirm)
interface YearRange {
start: number; // First year to show
end: number; // Last year to show
}

The value, minDate, maxDate, and initialDisplayedMonth props accept:

  • Date object: new Date(2024, 0, 15)
  • Epoch milliseconds: 1705276800000
  • ISO string: '2024-01-15' or '2024-01-15T00:00:00.000Z'
const [birthDate, setBirthDate] = useState<Date | null>(null);
<DatePicker
label="Date of Birth"
value={birthDate}
onConfirm={setBirthDate}
maxDate={new Date()} // No future dates
yearRange={{ start: 1920, end: new Date().getFullYear() }}
title="Select your birth date"
/>
const [appointmentDate, setAppointmentDate] = useState<Date | null>(null);
// Allow booking 1-30 days in advance
const minDate = new Date();
minDate.setDate(minDate.getDate() + 1);
const maxDate = new Date();
maxDate.setDate(maxDate.getDate() + 30);
<DatePicker
label="Appointment Date"
value={appointmentDate}
onConfirm={setAppointmentDate}
minDate={minDate}
maxDate={maxDate}
title="Select appointment date"
/>
const [date, setDate] = useState<Date | null>(null);
<DatePicker
label="Event Date"
value={date}
onChange={(d) => console.log('Selecting:', d)}
onConfirm={(d) => {
setDate(d);
console.log('Confirmed:', d);
}}
onCancel={() => console.log('Cancelled')}
/>

Start in text input mode instead of calendar:

<DatePicker
label="Date"
value={date}
onConfirm={setDate}
initialDisplayMode="input"
showModeToggle={true} // User can switch to calendar
/>
<DatePicker
label="Fecha"
value={date}
onConfirm={setDate}
title="Seleccionar fecha"
confirmLabel="Aceptar"
cancelLabel="Cancelar"
placeholder="Seleccione una fecha"
/>

Start the calendar on a specific month:

<DatePicker
label="Date"
value={date}
onConfirm={setDate}
initialDisplayedMonth={new Date(2025, 0, 1)} // January 2025
/>
const [checkIn, setCheckIn] = useState<Date | null>(null);
const [checkOut, setCheckOut] = useState<Date | null>(null);
<DatePicker
label="Check-in"
value={checkIn}
onConfirm={(d) => {
setCheckIn(d);
// Reset check-out if it's before new check-in
if (checkOut && d && checkOut < d) {
setCheckOut(null);
}
}}
minDate={new Date()}
/>
<DatePicker
label="Check-out"
value={checkOut}
onConfirm={setCheckOut}
minDate={checkIn || new Date()}
disabled={!checkIn}
/>