CalendarDatePicker

fun CalendarDatePicker(datePickerState: CalendarDatePickerState, label: String, value: String, expanded: Boolean, onValueChange: (String) -> Unit, onExpandedChange: (Boolean) -> Unit, onDismissRequest: () -> Unit, modifier: Modifier = Modifier, placeholderText: String = "", helperText: String = "", inputState: TextInputState = TextInputState.Enabled, keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, dayOfWeekNames: DayOfWeekNames = DayOfWeekNames.ENGLISH_ABBREVIATED, yearFormat: DateTimeFormat<YearMonth> = YearMonth.Format { year() }, monthFormat: DateTimeFormat<YearMonth> = YearMonth.Format { monthName(MonthNames.ENGLISH_FULL) }, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() })

Date picker - Calendar - Single date

Calendar pickers default to showing today’s date when opened and only one month is shown at a time. Calendar pickers allow users to navigate through months and years, however they work best when used for recent or near future dates. If a user needs to input a far distant or future date consider having the calendar default open to a more convenient day.

About the variant

In a single date picker a user has the option to either manually input a date in the text field or select one specific date from the menu calendar. It requires a day, month, and year to be selected.

Compose implementation

This composable uses kotlinx.datetime for date handling and formatting.

(From Date picker documentation)

Parameters

datePickerState

A CalendarDatePickerState that is used to control the state of the date picker.

label

Text that informs the user about the content they need to type in the field.

value

The input String text to be shown in the text input.

expanded

Whether the calendar menu is currently expanded.

onValueChange

Callback triggered when the input service updates the text. An updated text comes as a parameter of the callback.

onExpandedChange

Callback triggered when the expanded state of the calendar menu should be changed.

onDismissRequest

Callback triggered when the calendar menu should be dismissed.

modifier

Optional Modifier for this text input.

placeholderText

Optional text that provides hints or examples of what to type.

helperText

Optional helper text is pertinent information that assists the user in correctly completing a field. It is often used to explain the correct data format.

inputState

The interactive state of the text input.

keyboardOptions

Software keyboard options that contains configuration such as androidx.compose.ui.text.input.KeyboardType and androidx.compose.ui.text.input.ImeAction.

keyboardActions

when the input service emits an IME action, the corresponding callback is called. Note that this IME action may be different from what you specified in KeyboardOptions.imeAction.

dayOfWeekNames

Object providing the names of the days of the week to be displayed in the calendar.

yearFormat

The DateTimeFormat used to format the displayed year in the calendar.

monthFormat

The DateTimeFormat used to format the displayed month in the calendar.

interactionSource

The MutableInteractionSource representing the stream of androidx.compose.foundation.interaction.Interactions for this TextField. You can create and pass in your own remembered MutableInteractionSource if you want to observe androidx.compose.foundation.interaction.Interactions and customize the appearance / behavior of this TextField in different androidx.compose.foundation.interaction.Interactions.