# InlineDateTimePicker
Package: @mantine/dates
Import: import { InlineDateTimePicker } from '@mantine/dates';
Description: Inline date and time picker with range support

## DatePicker props

`InlineDateTimePicker` supports most of the [DatePicker](https://alpha.mantine.dev/llms/dates-date-picker.md) props.
Features that are not listed on this page are documented there.

## Usage

`InlineDateTimePicker` renders a calendar with a time picker inline, without a dropdown.
The value is applied when the submit button is pressed.
Change the button label with the `submitButtonLabel` prop or the same [DatesProvider](https://alpha.mantine.dev/llms/dates-getting-started.md#datesprovider) setting, and pass other props with `submitButtonProps`:

```tsx
import { InlineDateTimePicker } from '@mantine/dates';

function Demo() {
  return <InlineDateTimePicker />;
}
```


## With seconds

Set `withSeconds` prop to display seconds input in the time picker:

```tsx
import { InlineDateTimePicker } from '@mantine/dates';

function Demo() {
  return <InlineDateTimePicker withSeconds />;
}
```


## Range

Set `type="range"` to allow selecting a date and time range.
Two time inputs are rendered side by side with a range summary below them:

```tsx
import { InlineDateTimePicker } from '@mantine/dates';

function Demo() {
  return <InlineDateTimePicker type="range" />;
}
```


## Controlled range

```tsx
import { useState } from 'react';
import { InlineDateTimePicker } from '@mantine/dates';

function Demo() {
  const [value, setValue] = useState<[string | null, string | null]>([null, null]);

  return (
    <InlineDateTimePicker
      type="range"
      value={value}
      onChange={setValue}
    />
  );
}
```


## Controlling with useInlineDateTimePicker

`InlineDateTimePicker` component supports the [controller pattern](https://alpha.mantine.dev/llms/guides-controllers.md). Use the `useInlineDateTimePicker` hook to manage `InlineDateTimePicker` state.
The controller does not own the selected value, keep using `value` and `onChange` for it.
When the `controller` prop is set, the date, level and `defaultTimeValue` props of the component are ignored, pass them to `useInlineDateTimePicker` instead:

```tsx
import { useState } from 'react';
import { Button, Group, Stack, Text } from '@mantine/core';
import { InlineDateTimePicker, useInlineDateTimePicker } from '@mantine/dates';

function Demo() {
  const [value, setValue] = useState<string | null>(null);
  const controller = useInlineDateTimePicker({ defaultDate: '2024-06-15' });

  return (
    <Stack align="center">
      <Group justify="center">
        <Button variant="default" onClick={controller.previous}>
          Previous
        </Button>
        <Button variant="default" onClick={controller.next}>
          Next
        </Button>
        <Button
          variant="default"
          onClick={() => {
            controller.setLevel('month');
            controller.setTime('09:00');
            controller.focusTime('minutes');
          }}
        >
          Start at 9:00
        </Button>
      </Group>

      <InlineDateTimePicker
        value={value}
        onChange={setValue}
        controller={controller}
        maw={280}
      />

      <Text size="sm" c="dimmed">
        Time: {controller.getTime() || 'not set'}
      </Text>
    </Stack>
  );
}
```


`useInlineDateTimePicker` returns the navigation actions of [useCalendar](https://alpha.mantine.dev/llms/dates-calendar.md#controlling-with-usecalendar) together with time actions and queries:

```tsx
import { useState } from 'react';
import { InlineDateTimePicker, useInlineDateTimePicker } from '@mantine/dates';

function Demo() {
  const [value, setValue] = useState<string | null>(null);
  const controller = useInlineDateTimePicker({
    defaultDate: '2024-06-15', // -> date displayed when there is no value
    defaultTimeValue: '09:00', // -> time used when a date is picked with empty time inputs
    // date, onDateChange, level, defaultLevel, onLevelChange -> same as on useCalendar
    // time, onTimeChange, endTime, onEndTimeChange -> time inputs in controlled mode
  });

  // Navigation actions, same as useCalendar
  controller.next();
  controller.setLevel('month');

  // Time actions
  controller.setTime('10:30'); // -> sets the time input and the time of the value
  controller.setEndTime('18:00'); // -> end time with type="range"
  controller.focusTime('minutes'); // -> focuses a field of the time input
  controller.focusEndTime('hours');

  // Queries
  controller.getTime(); // -> time of the time input, also before a date is picked
  controller.getEndTime(); // -> time of the end time input with type="range"

  return (
    <InlineDateTimePicker value={value} onChange={setValue} controller={controller} />
  );
}
```

The time inputs are driven through the controller, `timePickerProps` and `endTimePickerProps` do not accept a `controller`.

## Value format

Use `valueFormat` prop to change the [dayjs format](https://day.js.org/docs/en/display/format) of the range preview:

```tsx
import { InlineDateTimePicker } from '@mantine/dates';

function Demo() {
  return <InlineDateTimePicker type="range" valueFormat="MMMM YYYY, DD HH:mm" />;
}
```



#### Props

**InlineDateTimePicker props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| allowDeselect | boolean | - | Determines whether user can deselect the date by clicking on selected item, applicable only when type="default" |
| allowSingleDateInRange | boolean | - | Determines whether a single day can be selected as range, applicable only when type="range" |
| ariaLabels | CalendarAriaLabels | - | `aria-label` attributes for controls on different levels |
| columnsToScroll | number | - | Number of columns to scroll with next/prev buttons, same as `numberOfColumns` if not set explicitly |
| controller | InlineDateTimePickerController | - | Controller returned by the `useInlineDateTimePicker` hook. When provided, the displayed date and level and the time inputs are owned by the controller and `date`, `defaultDate`, `onDateChange`, `level`, `defaultLevel`, `onLevelChange` and `defaultTimeValue` props are ignored |
| date | string \| Date | - | Displayed date in controlled mode |
| decadeLabelFormat | DecadeLabelFormat | "YYYY" | `dayjs` format for decade label or a function that returns decade label based on the date value |
| defaultDate | string \| Date | - | Initial displayed date in uncontrolled mode |
| defaultLevel | "month" \| "year" \| "decade" | - | Initial displayed level (uncontrolled) |
| defaultTimeValue | string | - | Default time value in `HH:mm` or `HH:mm:ss` format. Assigned to time when date is selected. |
| defaultValue | DateValue \| DatesRangeValue<DateValue> | - | Default value for uncontrolled component |
| enableKeyboardNavigation | boolean | true | Enable enhanced keyboard navigation (Ctrl/Cmd + Arrow keys for year navigation, Ctrl/Cmd + Shift + Arrow keys for decade navigation, Y key to open year view) |
| endTimePickerProps | Omit<TimePickerProps, "value" \| "defaultValue" \| "controller"> | - | Props passed down to the end time `TimePicker` component in range mode |
| excludeDate | (date: string) => boolean | - | Callback function to determine whether the day should be disabled |
| firstDayOfWeek | 0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6 | - | Number 0-6, where 0 – Sunday and 6 – Saturday. The default value is defined by `DatesProvider`. |
| fullWidth | boolean | false | Determines whether the list should take the full width of its container |
| getDayAriaLabel | (date: string) => string | - | Assigns `aria-label` to `Day` components based on date |
| getDayProps | (date: string) => Omit<Partial<DayProps>, "vars" \| "classNames" \| "styles"> & DataAttributes | - | Passes props down to `Day` components |
| getMonthControlProps | (date: string) => Partial<PickerControlProps> & DataAttributes | - | Passes props down month picker control |
| getYearControlProps | (date: string) => Partial<PickerControlProps> & DataAttributes | - | Passes props down to year picker control based on date |
| headerControlsOrder | ("next" \| "previous" \| "level")[] | ['previous', 'level', 'next'] | Controls order |
| hideOutsideDates | boolean | false | Determines whether outside dates should be hidden |
| hideWeekdays | boolean | false | Determines whether weekdays row should be hidden |
| highlightToday | boolean | false | Determines whether today should be highlighted with a border |
| labelSeparator | string | '–' | Separator between range values, overrides `labelSeparator` from `DatesProvider` settings |
| level | "month" \| "year" \| "decade" | - | Current displayed level (controlled) |
| locale | string | - | Dayjs locale, defaults to value defined in DatesProvider |
| maxDate | string \| Date | - | Max date |
| maxLevel | "month" \| "year" \| "decade" | - | - |
| minDate | string \| Date | - | Min date |
| monthLabelFormat | string \| ((date: string) => string) | "MMMM YYYY" | dayjs label format to display month label or a function that returns month label based on month value |
| monthsListFormat | string \| ((date: string) => string) | "MMM" | `dayjs` format for months list or a function that returns month label based on the date value |
| nextIcon | React.ReactNode | - | Change next icon |
| nextLabel | string | - | Next button `aria-label` |
| numberOfColumns | number | 1 | Number of columns displayed next to each other |
| onChange | (value: DatePickerValue<Type, string>) => void | - | Called when value changes |
| onDateChange | (date: string) => void | - | Called when date changes |
| onLevelChange | (level: CalendarLevel) => void | - | Called when level changes |
| onMonthMouseEnter | (event: MouseEvent<HTMLButtonElement, MouseEvent>, date: string) => void | - | Called when mouse enters month control |
| onMonthSelect | (date: string) => void | - | Called when user selects month |
| onNextDecade | (date: string) => void | - | Called when the next decade button is clicked |
| onNextMonth | (date: string) => void | - | Called when the next month button is clicked |
| onNextYear | (date: string) => void | - | Called when the next year button is clicked |
| onPreviousDecade | (date: string) => void | - | Called when the previous decade button is clicked |
| onPreviousMonth | (date: string) => void | - | Called when the previous month button is clicked |
| onPreviousYear | (date: string) => void | - | Called when the previous year button is clicked |
| onSubmit | () => void | - | Called when the submit button is clicked |
| onYearMouseEnter | (event: MouseEvent<HTMLButtonElement, MouseEvent>, date: string) => void | - | Called when mouse enters year control |
| onYearSelect | (date: string) => void | - | Called when user selects year |
| presets | DatePickerPreset<Type>[] | - | Predefined values to pick from |
| previousIcon | React.ReactNode | - | Change previous icon |
| previousLabel | string | - | Previous button `aria-label` |
| renderDay | (date: string) => React.ReactNode | - | Controls day value rendering |
| size | MantineSize | 'sm' | Component size |
| submitButtonLabel | string | 'Save' | Label of the submit button, overrides `submitButtonLabel` from `DatesProvider` settings |
| submitButtonProps | ButtonProps & ElementProps<"button"> | - | Props passed down to the submit button |
| timePickerProps | Omit<TimePickerProps, "value" \| "defaultValue" \| "controller"> | - | Props passed down to `TimePicker` component |
| type | "default" \| "multiple" \| "range" | - | Picker type: range, multiple or default |
| value | DateValue \| DatesRangeValue<DateValue> | - | Value for controlled component |
| valueFormat | string \| ((date: string) => string) | "DD/MM/YYYY HH:mm" | `dayjs` format for range display, or a function that receives the value as a `YYYY-MM-DD HH:mm:ss` string and returns the formatted value |
| weekdayFormat | string \| ((date: string) => string) | 'dd' | `dayjs` format string or a function that returns weekday label for the given date |
| weekendDays | (0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6)[] | - | Indices of weekend days, 0-6, where 0 is Sunday and 6 is Saturday. The default value is defined by `DatesProvider`. |
| withCellSpacing | boolean | true | Determines whether controls should be separated |
| withNativeLevelSelect | boolean | false | Determines whether level select controls should be rendered as native `<select>` elements |
| withSeconds | boolean | false | Determines whether the seconds input should be displayed |
| withWeekNumbers | boolean | false | Determines whether week numbers should be displayed |
| yearLabelFormat | string \| ((date: string) => string) | "YYYY" | dayjs label format to display year label or a function that returns year label based on year value |
| yearsListFormat | string \| ((date: string) => string) | "YYYY" | `dayjs` format for years list or a function that returns year label based on the date value |
| yearsSelectRange | [number, number] | - | Year range for native level select, tuple of `[startYear, endYear]`. Defaults to `[currentYear - 100, currentYear + 50]` or values derived from `minDate`/`maxDate` if set. |


#### Styles API

InlineDateTimePicker component supports Styles API. With Styles API, you can customize styles of any inner element. Follow the documentation to learn how to use CSS modules, CSS variables and inline styles to get full control over component styles.

**InlineDateTimePicker selectors**

| Selector | Static selector | Description |
|----------|----------------|-------------|
| calendarHeader | .mantine-InlineDateTimePicker-calendarHeader | Calendar header root element |
| calendarHeaderControl | .mantine-InlineDateTimePicker-calendarHeaderControl | Previous/next calendar header controls |
| calendarHeaderControlIcon | .mantine-InlineDateTimePicker-calendarHeaderControlIcon | Icon of previous/next calendar header controls |
| calendarHeaderLevel | .mantine-InlineDateTimePicker-calendarHeaderLevel | Level control (changes levels when clicked, month -> year -> decade) |
| monthThead | .mantine-InlineDateTimePicker-monthThead | thead element of month table |
| monthRow | .mantine-InlineDateTimePicker-monthRow | tr element of month table |
| monthTbody | .mantine-InlineDateTimePicker-monthTbody | tbody element of month table |
| monthCell | .mantine-InlineDateTimePicker-monthCell | td element of month table |
| month | .mantine-InlineDateTimePicker-month | Month table element |
| weekdaysRow | .mantine-InlineDateTimePicker-weekdaysRow | Weekdays tr element |
| weekday | .mantine-InlineDateTimePicker-weekday | Weekday th element |
| day | .mantine-InlineDateTimePicker-day | Month day control |
| weekNumber | .mantine-InlineDateTimePicker-weekNumber | Week number td element |
| weekControl | .mantine-InlineDateTimePicker-weekControl | Week control button inside week number cell, rendered only in WeekPicker |
| levelsGroup | .mantine-InlineDateTimePicker-levelsGroup | Group of levels |
| datePickerRoot | .mantine-InlineDateTimePicker-datePickerRoot | Date picker root element, contains calendar and presets |
| presetsList | .mantine-InlineDateTimePicker-presetsList | Presets wrapper element |
| presetButton | .mantine-InlineDateTimePicker-presetButton | Preset button |
| root | .mantine-InlineDateTimePicker-root | Root element |
| content | .mantine-InlineDateTimePicker-content | Wrapper around the calendar and time inputs, placed next to the presets list |
| timeWrapper | .mantine-InlineDateTimePicker-timeWrapper | Wrapper around time input and submit button |
| timeInput | .mantine-InlineDateTimePicker-timeInput | TimeInput |
| submitButton | .mantine-InlineDateTimePicker-submitButton | Submit button |
| rangeTimeWrapper | .mantine-InlineDateTimePicker-rangeTimeWrapper | Wrapper around two time inputs and submit button in range mode |
| rangeTimeInput | .mantine-InlineDateTimePicker-rangeTimeInput | Time input in range mode |
| rangeInfo | .mantine-InlineDateTimePicker-rangeInfo | Range dates preview in range mode |
