Calendar

A Jetpack Compose calendar component. Supports single date selection, date range selection, date restriction modes, month/year picker dialogs, and full color customization.

Calendar renders a month grid with navigation arrows, clickable month/year selector chips, and a day grid. It comes in two flavors of the primary composable — a convenience overload for single-date selection and a selectionMode-based overload that additionally supports range selection.

Basic Usage

The simplest way to use the calendar is through the single-date convenience overload. Pass selectedDate and an onDateSelected callback.

Single Selection Mode

Use CalendarSelectionMode.Single with the selectionMode parameter for explicit single-date selection. This is the recommended approach when you need the full selectionMode parameter — for instance when combining it with other CalendarSelectionMode variants in your codebase.

Date Restriction Modes

Use dateSelectionMode to restrict which dates are clickable. Disabled dates are rendered with a muted color and cannot be tapped.

Past or Today

Future or Today

DateSelectionMode values and their behavior:

ModeClickable dates
All (default)Every date in the grid
PastOrTodayToday and any date before today
FutureOrTodayToday and any date after today

Range Calendar

Pass CalendarSelectionMode.Range to enable range selection. The first tap sets the start date, the second tap sets the end date and fires onRangeSelected. Tapping again after a complete range resets and starts a new selection. If the second tap is before the first, the dates are automatically swapped.

Initial Month

By default the calendar opens on the current month. Use initialMonth to open on a specific YearMonth.

initialMonth is only used on first composition. To programmatically navigate months after the calendar is rendered, hoist the state into a YearMonth variable and pass it each time.

Custom Styles

Pass a CalendarStyle to the colors parameter to override any color token. Use CalendarDefaults.colors { } to get a pre-filled style based on the current theme and apply copy(...) inside the lambda for targeted overrides.


API Reference

Calendar (convenience overload)

Single-date selection overload. Internally wraps selectedDate + onDateSelected into CalendarSelectionMode.Single.

ParameterTypeDefaultDescription
modifierModifierModifierApplied to the calendar container.
selectedDateLocalDate?nullThe currently selected date.
onDateSelected(LocalDate) -> UnitCalled when the user taps a date.
initialMonthYearMonthYearMonth.now()The month shown on first render.
dateSelectionModeDateSelectionModeDateSelectionMode.AllControls which dates are clickable.
colorsCalendarStyleCalendarDefaults.colors()Color tokens for the calendar.

Calendar (selectionMode overload)

Full overload used for both single and range selection.

ParameterTypeDefaultDescription
modifierModifierModifierApplied to the calendar container.
selectionModeCalendarSelectionModeSingle or range selection configuration.
initialMonthYearMonthYearMonth.now()The month shown on first render.
dateSelectionModeDateSelectionModeDateSelectionMode.AllControls which dates are clickable.
colorsCalendarStyleCalendarDefaults.colors()Color tokens for the calendar.

DateSelectionMode

Enum that restricts which dates are tappable.

ValueDescription
AllAll dates are enabled.
PastOrTodayOnly today and past dates are enabled.
FutureOrTodayOnly today and future dates are enabled.

CalendarSelectionMode

Sealed interface defining the selection behavior.

CalendarSelectionMode.Single

ParameterTypeDefaultDescription
selectedDateLocalDate?nullThe currently selected date.
onDateSelected(LocalDate) -> UnitCalled when the user taps a date.

CalendarSelectionMode.Range

ParameterTypeDefaultDescription
selectedRangeDateRange?nullThe currently selected date range.
onRangeSelected(DateRange) -> UnitCalled when the user completes a range selection.

DateRange

data class DateRange(val start: LocalDate, val end: LocalDate)

Holds the start and end dates of a range selection.

YearMonth

Helper class used for calendar navigation. Provides factory methods and arithmetic operators.

MemberDescription
YearMonth.now()Returns the current year-month from the system clock.
YearMonth.from(date: LocalDate)Creates a YearMonth from a LocalDate.
plusMonths(n)Returns a new YearMonth advanced by n months.
minusMonths(n)Returns a new YearMonth reduced by n months.
atDay(day)Returns a LocalDate for the given day in this month.
lengthOfMonth()Number of days in the month (leap-year aware).

CalendarStyle

All color tokens used to render the calendar. Obtain a default instance via CalendarDefaults.colors() and override fields using CalendarDefaults.colors { copy(...) }.

FieldTypeDescription
backgroundColorBackground of the calendar container.
borderColorBorder around the calendar container.
leftIconTintColorTint of the previous-month arrow icon.
rightIconTintColorTint of the next-month arrow icon.
monthTextColorText color of the month selector chip.
yearTextColorText color of the year selector chip.
monthSelectorBorderColorBorder of the month selector chip.
yearSelectorBorderColorBorder of the year selector chip.
weekDaysTextColorText color of the weekday header row (Sun–Sat).
dateCellBgStyleDateCellBackgroundStyleBackground colors for individual day cells.
dateCellTextStyleDateCellTextStyleText colors for individual day cells.
dialogStyleSelectorDialogStyleColors for the month/year picker dialogs.

DateCellBackgroundStyle

FieldTypeDescription
selectedDateColorBackground of the selected date cell.
todayUnselectedBgColorBackground of today's cell when not selected.
onPressedColorBackground color during press animation.
defaultDateCellColorBackground of a normal, unselected date cell.
rangeEndpointBgColorBackground of the range start/end cells.
inRangeBgColorBackground of cells between the range endpoints.

DateCellTextStyle

FieldTypeDescription
selectedDateColorText color of the selected date.
todayUnselectedColorText color of today when not selected.
currentMonthUnselectedColorText color of normal, unselected days in the current month.
currentMonthDisabledColorText color of disabled days in the current month.
previousAndNextDateMonthColorText color of days spilling from the previous/next month.
previousAndNextDateMonthDisabledColorText color of disabled days outside the current month.
rangeEndpointTextColorText color of the range start/end cells.
inRangeTextColorText color of cells between the range endpoints.

SelectorDialogStyle

Shared color scheme for the month and year picker dialogs.

FieldTypeDescription
selectedBgColorBackground of the currently selected item.
selectedTextColorText color of the currently selected item.
unselectedBgColorBackground of unselected items.
unselectedTextColorText color of unselected items.

CalendarDefaults

MemberDescription
colors()Returns a CalendarStyle populated from the current Material theme.
colors { copy(...) }Returns a CalendarStyle with selective overrides applied via a lambda.
Edit this page on GitHub