Skip to main content

Datepicker

Datepicker provides date selection through a modal calendar popup. It supports single date and date range selection modes.

Import​

import { Datepicker, RangeDatepicker } from '@ui-kitten/components';

Basic Usage​

Single Date​

import React, { useState } from 'react';
import { Layout, Datepicker } from '@ui-kitten/components';

const DatepickerExample = () => {
const [date, setDate] = useState(new Date());

return (
<Layout style={{ flex: 1, padding: 16 }}>
<Datepicker
label="Select Date"
caption="Choose a delivery date"
date={date}
onSelect={(nextDate) => setDate(nextDate)}
/>
</Layout>
);
};

Date Range​

import React, { useState } from 'react';
import { Layout, RangeDatepicker } from '@ui-kitten/components';

const RangeDatepickerExample = () => {
const [range, setRange] = useState({});

return (
<Layout style={{ flex: 1, padding: 16 }}>
<RangeDatepicker
label="Select Range"
range={range}
onSelect={(nextRange) => setRange(nextRange)}
/>
</Layout>
);
};

Props​

Datepicker​

PropertyTypeDefaultDescription
dateDateundefinedThe currently selected date.
onSelect(date: Date) => void-Called when a date is selected.
minDateundefinedMinimum selectable date.
maxDateundefinedMaximum selectable date.
dateServiceDateServiceNativeDateServiceCustom date service for localization and formatting.
labelstring | number | (props) => ReactElementundefinedLabel displayed above the input.
captionstring | number | (props) => ReactElementundefinedCaption displayed below the input.
placeholderstring | number | (props) => ReactElement'dd/mm/yyyy'Placeholder displayed when no date is selected.
status'basic' | 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'control''basic'Status of the control.
size'small' | 'medium' | 'large''medium'Size of the control.
accessoryLeft(props) => ReactElementundefinedRender function for the accessory shown at the start of the control.
accessoryRight(props) => ReactElementundefinedRender function for the accessory shown at the end of the control.
controlStyleViewStyleundefinedStyle applied to the control that opens the calendar.
placementPopoverPlacement | string'bottom start'Position of the calendar relative to the control.
backdropStyleViewStyleundefinedStyle applied to the backdrop behind the calendar.
autoDismissbooleantrueWhether the calendar closes as soon as a date is selected.
onFocus() => voidundefinedCalled when the calendar opens.
onBlur() => voidundefinedCalled when the calendar closes.

Datepicker embeds a Calendar and accepts all of its presentation properties too — filter, initialVisibleDate, boundingMonth, startView, title, renderDay, renderFooter, renderMonth, renderYear, renderArrowLeft, renderArrowRight and onVisibleDateChange — plus all React Native TouchableOpacity props.

Datepicker exposes an imperative API through a ref typed as DatepickerRef:

MethodSignatureDescription
focus() => voidOpens the calendar.
blur() => voidCloses the calendar.
isFocused() => booleanWhether the calendar is open.
clear() => voidClears the selected date.
scrollToToday() => voidScrolls the calendar to the current date.
scrollToDate(date: Date) => voidScrolls the calendar to a given date.
getCalendarVisibleDate() => Date | undefinedReturns the currently visible calendar date.

RangeDatepicker​

PropertyTypeDefaultDescription
range{ startDate?: Date, endDate?: Date }{}The currently selected date range.
onSelect(range: { startDate: Date, endDate: Date }) => void-Called when a range is selected.
minDateundefinedMinimum selectable date.
maxDateundefinedMaximum selectable date.
dateServiceDateServiceNativeDateServiceCustom date service for localization and formatting.
labelstring | number | (props) => ReactElementundefinedLabel displayed above the input.
captionstring | number | (props) => ReactElementundefinedCaption displayed below the input.

RangeDatepicker accepts the same control and calendar properties as Datepicker, and exposes the same ref API, typed as RangeDatepickerRef. Note that it does not accept autoDismiss — a range needs two taps, so the calendar stays open until both ends are picked.

Storybook​

Live examples coming soon via Storybook.