InlineDateTimePicker

Inline date and time picker with range support

DatePicker props

InlineDateTimePicker supports most of the DatePicker 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 setting, and pass other props with submitButtonProps:

MoTuWeThFrSaSu
:
import { InlineDateTimePicker } from '@mantine/dates';

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

With seconds

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

MoTuWeThFrSaSu
::
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:

MoTuWeThFrSaSu

:
:
import { InlineDateTimePicker } from '@mantine/dates';

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

Controlled range

MoTuWeThFrSaSu

:
:
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. 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:

MoTuWeThFrSaSu
:

Time: not set

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 together with time actions and queries:

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 of the range preview:

MoTuWeThFrSaSu

:
:
import { InlineDateTimePicker } from '@mantine/dates';

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