Input · DatePicker

DatePicker

The date selector is used to help the user select a compliant, formatted date (time) or date (time) range.

Demos

How to import

<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

Basic Use

Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

<template>
    <DatePicker @change="(_date, dateString) => console.log(dateString)" />
</template>

Picker Density

The density can be used to control the size of the picker panel. The compact is the small size and the default is the default size. Support after v1.17.0.



~
Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

<template>
    <div>
        <DatePicker density="compact" type="dateTime" />
        <br />
        <br />
        <DatePicker density="compact" :style="{ width: '260px' }" type="dateRange" />
    </div>
</template>

Multiple Date Selection

Set Multiple to true, can choose multiple dates.

Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

<template>
    <DatePicker multiple :style="{ width: '240px' }" />
</template>

Date and Time Selection

Set type to dateTime, can choose date and time.
Starting from version V2.22.0, we changed the default mode of ScrollItem in TimePicker from wheel to normal. If you want to apply the infinite scrolling effect again, you can enable it by passing in a specific configuration through timePickerOpts.

默认日期与时间选择



开启时间列表无限循环

Code
<script setup lang="ts">
    import { DatePicker, type DatePickerTimePickerOpts } from '@fibrous/semi-ui-vue';

    const timePickerOpts: DatePickerTimePickerOpts = { scrollItemProps: { mode: 'wheel', cycled: true } };
</script>

<template>
    <h4>默认日期与时间选择</h4>
    <DatePicker type="dateTime" />
    <br />
    <br />
    <h4>开启时间列表无限循环</h4>
    <DatePicker :timePickerOpts="timePickerOpts" type="dateTime" />
</template>

Date Range Selection

Set type to dateRange, can choose the date range.

~
Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

<template>
    <DatePicker :style="{ width: '260px' }" type="dateRange" @change="console.log" />
</template>

Date Time Range Selection

Set type to dateTimeRange, can choose the date range and choose time;

~
~
Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';

    const defaultPickerValue = [new Date('2022-08-08 00:00'), new Date('2022-08-09 12:00')];
</script>

<template>
    <DatePicker :style="{ width: '400px', marginBottom: '8px' }" type="dateTimeRange" @change="console.log" />
    <DatePicker :defaultPickerValue="defaultPickerValue" :style="{ width: '400px' }" type="dateTimeRange" @change="console.log" />
</template>

Input in Panel

Use insetInput to control whether the date panel is inset with the input box, the default is false. Supported since v2.7.0. Inset input boxes are suitable for the following scenarios:

  • Date and time selection, you can directly input the time through the embedded input box, no need to select the time through the scroll wheel
  • With a custom trigger and range selection, use the inset input box to modify the start and end dates independently

After insetInput is turned on, it includes the following functions:

  • After clicking the trigger, the panel will pop up in the original position by default. You can customize the popup position by position
  • Click the embedded date input box, the panel switches to date selection; click the embedded time input box, the panel switches to time selection
  • Consistent with the external input box, if an illegal date is entered, the date will return to the previous legal date after the panel is closed




~


~








Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

<template>
    <div>
        <DatePicker insetInput type="date" />
        <br />
        <br />
        <DatePicker insetInput type="dateTime" />
        <br />
        <br />
        <DatePicker insetInput :style="{ width: '260px' }" type="dateRange" />
        <br />
        <br />
        <DatePicker insetInput :style="{ width: '400px' }" type="dateTimeRange" />
        <br />
        <br />
        <DatePicker insetInput placeholder="请选择年月" :style="{ width: '140px' }" type="month" />
        <br />
        <br />
        <DatePicker insetInput placeholder="请选择年月范围" :style="{ width: '200px' }" type="monthRange" />
        <br />
        <br />
        <DatePicker insetInput position="bottomLeft" type="date" />
        <br />
        <br />
        <DatePicker format="yyyy-MM-dd HH:mm" insetInput type="dateTime" />
    </div>
</template>

Synchronously switch months

version:>= 1.28.0

In the scenario of range selection, turning on syncSwitchMonth means to switch the two panels simultaneously. The default is false.

Note: Clicking the year button will also switch the two panels synchronously. Switching the year and month from the scroll wheel will not switch the panels synchronously. This ensures the user's ability to select months at non-fixed intervals.

~
Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

<template>
    <DatePicker :style="{ width: '400px' }" syncSwitchMonth type="dateTimeRange" />
</template>

Panel Change Callback

version:>=1.28.0

The panelChange event is emitted when the month or year of the panel is changed.

~
Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';

    const onPanelChange = (date: Date | Date[], dateString: string | string[]) => console.log(date, dateString);
</script>

<template>
    <DatePicker :style="{ width: '400px' }" syncSwitchMonth type="dateTimeRange" @panelChange="onPanelChange" />
</template>

Select Week

daterange is used with startDateOffset and endDateOffset to select range with single click, such as weekly selection and biweekly selection. Support after v1.10.0.

选择自然周

~


选择双周

~


选择当前日和后6日

~


Code
<script setup lang="ts">
    import * as dateFns from 'date-fns';
    import { DatePicker } from '@fibrous/semi-ui-vue';

    function handleChange(date: Date | Date[] | undefined) {
        console.log('date changed', date);
    }

    const startOfWeek = (date: Date) => dateFns.startOfWeek(date, { weekStartsOn: 1 });
    const endOfWeek = (date: Date) => dateFns.endOfWeek(date, { weekStartsOn: 1 });
    const endOfNextWeek = (date: Date) => dateFns.add(endOfWeek(date), { days: 7 });
    const sixDaysLater = (date: Date) => dateFns.add(date, { days: 6 });
</script>

<template>
    <div>
        <h4>选择自然周</h4>
        <DatePicker :endDateOffset="endOfWeek" :startDateOffset="startOfWeek" :style="{ width: '260px' }" type="dateRange" :weekStartsOn="1" @change="handleChange" />
        <br />
        <br />
        <h4>选择双周</h4>
        <DatePicker :endDateOffset="endOfNextWeek" :startDateOffset="startOfWeek" :style="{ width: '260px' }" type="dateRange" :weekStartsOn="1" @change="handleChange" />
        <br />
        <br />
        <h4>选择当前日和后6日</h4>
        <DatePicker :endDateOffset="sixDaysLater" :style="{ width: '260px' }" type="dateRange" :weekStartsOn="1" @change="handleChange" />
        <br />
        <br />
    </div>
</template>

Selection

Version: > = 0.21.0

Set type to month, can make year-to-month selection.

Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';

    const defaultValue = new Date(2024, 4, 6, 10, 30, 0);
</script>

<template>
    <DatePicker :defaultValue="defaultValue" :style="{ width: '140px' }" type="month" />
</template>

Year and Month Range Selection

version: >= 2.32.0

Set type to monthRange to select the year and month range, small size and quick panel are not supported yet.

Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';
</script>

<template>
    <DatePicker :style="{ width: '200px' }" type="monthRange" />
</template>

Year Selection

Set type to year to select a year. The panel has a single year column, the selected value is January 1 of that year, and the default format is yyyy. disabledDate decides whether a year can be picked from January 1 of that year.

Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';

    const defaultValue = new Date(2024, 4, 6, 10, 30, 0);
</script>

<template>
    <DatePicker :defaultValue="defaultValue" :style="{ width: '140px' }" type="year" />
</template>

Confirm Date and Time Selection

Version: > = 0.18.0

For the selection of "datetime" (type = "dateTime") or "datetime range" (type = "dateTimeRange"), you can confirm it before writing the value into the input box. You can pass NeedConfirm = true to enable this behavior.

At the same time, the click events of the "confirm" and "cancel" buttons are supported.

The following example listens to three events: change, confirm and cancel, and you can open the console to see the difference in print information.

Note: When opening needConfirm, you need to click the cancel button to close the panel, and clicking the blank area will no longer close the panel (v2.2.0)

Code
<script setup lang="ts">
    import { DatePicker, type DatePickerEmits } from '@fibrous/semi-ui-vue';

    const onConfirm = (...args: DatePickerEmits['confirm']) => {
        console.log('Confirmed: ', ...args);
    };
    const onCancel = (...args: DatePickerEmits['cancel']) => {
        console.log('Canceled: ', ...args);
    };
    const onChange = (...args: DatePickerEmits['change']) => {
        console.log('Changed: ', ...args);
    };
</script>

<template>
    <DatePicker needConfirm type="dateTime" @cancel="onCancel" @change="onChange" @confirm="onConfirm" />
</template>

Date and Time Selection with Shortcuts

Pass parameter Presets to set shortcuts for date selection.

Code
<script setup lang="ts">
    import { DatePicker, type DatePickerPresetsType } from '@fibrous/semi-ui-vue';

    const presets: DatePickerPresetsType = [
        {
            text: 'Today',
            start: () => new Date(),
            end: () => new Date(),
        },
        () => ({
            text: 'Tomorrow',
            start: new Date(new Date().valueOf() + 1000 * 3600 * 24),
            end: new Date(new Date().valueOf() + 1000 * 3600 * 24),
        }),
    ];
</script>

<template>
    <DatePicker presetPosition="left" :presets="presets" type="dateTime" />
</template>

Render TopSlot/BottomSlot

With the #topSlot and #bottomSlot slots, you can customize the rendering of the top and bottom extra areas. The #leftSlot and #rightSlot slots render the left and right extra areas.









~


Code
<script setup lang="ts">
    import { computed, ref } from 'vue';
    import { IconBulb } from '@fibrous/semi-icons-vue';
    import { DatePicker, Space, TabPane, Tabs, Typography, type DatePickerValueType } from '@fibrous/semi-ui-vue';

    const { Text } = Typography;

    const uedDisabledDate = (currentDate?: Date) => !!currentDate && currentDate.getDate() > 10 && currentDate.getDate() < 15;
    const testDisabledDate = (currentDate?: Date) => !!currentDate && currentDate.getDate() > 15 && currentDate.getDate() < 25;

    const activeTab = ref('1');
    const date = ref<DatePickerValueType>();
    const disabledDate = computed(() => (activeTab.value === '1' ? uedDisabledDate : testDisabledDate));
</script>

<template>
    <div>
        <DatePicker v-model="date" :disabledDate="disabledDate" dropdownClassName="components-datepicker-demo-slot" placeholder="请选择排期">
            <template #topSlot>
                <Tabs v-model:activeKey="activeTab" size="small" :style="{ padding: '12px 20px 0' }" @change="date = undefined">
                    <TabPane itemKey="1">
                        <template #tab>UED 排期</template>
                    </TabPane>
                    <TabPane itemKey="2">
                        <template #tab>测试排期</template>
                    </TabPane>
                </Tabs>
            </template>
        </DatePicker>
        <br />
        <br />
        <DatePicker placeholder="请选择发版时间">
            <template #bottomSlot>
                <Space :style="{ padding: '12px 20px' }">
                    <IconBulb :style="{ color: 'var(--semi-amber-5)' }" />
                    <Text strong :style="{ color: 'var(--semi-color-text-2)' }">定版前请阅读</Text>
                    <Text :link="{ href: 'https://semi.design/', target: '_blank' }">发版须知</Text>
                </Space>
            </template>
        </DatePicker>
        <br />
        <br />
        <DatePicker placeholder="请选择年月" type="month">
            <template #bottomSlot>
                <Space :style="{ padding: '12px 20px' }">
                    <IconBulb :style="{ color: 'var(--semi-amber-5)' }" />
                    <Text strong :style="{ color: 'var(--semi-color-text-2)' }">请阅读</Text>
                    <Text :link="{ href: 'https://semi.design/', target: '_blank' }">须知</Text>
                </Space>
            </template>
        </DatePicker>
        <br />
        <br />
        <DatePicker density="compact" dropdownClassName="components-datepicker-demo-slot" placeholder="小尺寸">
            <template #topSlot>
                <Tabs v-model:activeKey="activeTab" size="small" :style="{ padding: '8px 12px 0' }" @change="date = undefined">
                    <TabPane itemKey="1">
                        <template #tab>UED 排期</template>
                    </TabPane>
                    <TabPane itemKey="2">
                        <template #tab>测试排期</template>
                    </TabPane>
                </Tabs>
            </template>
            <template #bottomSlot>
                <Space :style="{ padding: '8px 12px' }">
                    <IconBulb :style="{ color: 'var(--semi-amber-5)' }" />
                    <Text strong :style="{ color: 'var(--semi-color-text-2)' }">定版前请阅读</Text>
                    <Text :link="{ href: 'https://semi.design/', target: '_blank' }">发版须知</Text>
                </Space>
            </template>
        </DatePicker>
        <br />
        <br />
        <DatePicker placeholder="请选择时间范围" :style="{ width: '400px' }" type="dateTimeRange">
            <template #bottomSlot>
                <Space :style="{ padding: '12px 20px' }">
                    <IconBulb :style="{ color: 'var(--semi-amber-5)' }" />
                    <Text strong :style="{ color: 'var(--semi-color-text-2)' }">定版前请阅读</Text>
                    <Text :link="{ href: 'https://semi.design/', target: '_blank' }">发版须知</Text>
                </Space>
            </template>
        </DatePicker>
        <br />
        <br />
    </div>
</template>
.components-datepicker-demo-slot {
    .semi-tabs-content {
        padding: 0;
    }

    .semi-tabs-bar-line.semi-tabs-bar-top {
        border-bottom: none;
    }
}

Disable Date Selection

Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';

    const defaultValue = new Date(2024, 4, 6, 10, 30, 0);
</script>

<template>
    <DatePicker :defaultValue="defaultValue" disabled type="dateTime" />
</template>

Disable Partial Date or Time

Pass in disabledDate to disable the specified date, pass in disabledTime to disable the specified time, and with defaultPickerValue you can specify the year and month when the panel is opened.

disabledDate anddisabledTime, the accepted input parameters are the current date, the former returns a boolean value, the latter returns an object It will be directly passed to the TimePicker component.

禁用时间:禁用今天下午5-6点

禁用时间:两个面板禁用不同时间

~

禁用日期:禁用下个月28号之前的所有日期

~
Code
<script setup lang="ts">
    import * as dateFns from 'date-fns';
    import { range } from 'es-toolkit';
    import { DatePicker, type DatePickerDisabledDateType, type DatePickerDisabledTimeType } from '@fibrous/semi-ui-vue';

    const nextValidMonth = new Date();
    nextValidMonth.setMonth((nextValidMonth.getMonth() + 1) % 12);

    const disabledTime: DatePickerDisabledTimeType = (date) =>
        // With type dateTime, date is a single Date
        dateFns.isToday(date as Date)
            ? {
                  disabledHours: () => [17, 18],
                  disabledMinutes: (hour) => (19 === hour ? range(0, 10, 1) : []),
                  disabledSeconds: (hour, minute) => (hour === 20 && minute === 20 ? range(0, 20, 1) : []),
              }
            : {};

    const disabledTime2: DatePickerDisabledTimeType = (_date, panelType) => (panelType === 'left' ? { disabledHours: () => [17, 18] } : { disabledHours: () => [12, 13, 14, 15, 16, 17, 18] });

    const disabledDate: DatePickerDisabledDateType = (date) => {
        const deadDate = new Date();
        const month = deadDate.getMonth();
        deadDate.setDate(28);
        deadDate.setMonth((month + 1) % 12);
        return !!date && date.getTime() < deadDate.getTime();
    };
</script>

<template>
    <div>
        <div>
            <h4>禁用时间:禁用今天下午5-6点</h4>
            <DatePicker :disabledTime="disabledTime" :hideDisabledOptions="false" type="dateTime" />
        </div>
        <div>
            <h4>禁用时间:两个面板禁用不同时间</h4>
            <DatePicker :disabledTime="disabledTime2" :hideDisabledOptions="false" :style="{ width: '400px' }" type="dateTimeRange" />
        </div>
        <div>
            <h4>禁用日期:禁用下个月28号之前的所有日期</h4>
            <DatePicker :defaultPickerValue="nextValidMonth" :disabledDate="disabledDate" :style="{ width: '400px' }" type="dateTimeRange" />
        </div>
    </div>
</template>

When type contains range, the date can be disabled dynamically according to the rangeStart. The options parameter is supported after 1.9.0

动态禁用日期:禁止选择之前的日期

~
Code
<script setup lang="ts">
    import * as dateFns from 'date-fns';
    import { DatePicker, type DatePickerDisabledDateType } from '@fibrous/semi-ui-vue';

    const disabledDate: DatePickerDisabledDateType = (date, options) => {
        if (!date || !options?.rangeStart) {
            return false;
        }
        return dateFns.isBefore(date, dateFns.parseISO(options.rangeStart));
    };
</script>

<template>
    <div>
        <h4>动态禁用日期:禁止选择之前的日期</h4>
        <DatePicker :disabledDate="disabledDate" :style="{ width: '260px' }" type="dateRange" />
    </div>
</template>

When type contains range, dates can be disabled based on the focus state. The focus state is passed through the rangeInputFocus parameter in options.

开始日期禁用今天前2日和后2日,结束日期禁用今天前3天和后3天

~
Code
<script setup lang="ts">
    import * as dateFns from 'date-fns';
    import { DatePicker, type DatePickerDisabledDateType } from '@fibrous/semi-ui-vue';

    const today = new Date();

    const disabledDate: DatePickerDisabledDateType = (date, options) => {
        if (!date) {
            return false;
        }
        const rangeInputFocus = options?.rangeInputFocus;
        const baseDate = dateFns.set(today, { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 });
        if (rangeInputFocus === 'rangeStart') {
            return dateFns.subDays(baseDate, 2) <= date && date <= dateFns.addDays(baseDate, 2);
        } else if (rangeInputFocus === 'rangeEnd') {
            return dateFns.subDays(baseDate, 3) <= date && date <= dateFns.addDays(baseDate, 3);
        }
        return false;
    };
</script>

<template>
    <div>
        <h4>开始日期禁用今天前2日和后2日,结束日期禁用今天前3天和后3天</h4>
        <DatePicker :defaultPickerValue="today" :disabledDate="disabledDate" :motion="false" type="dateRange" />
    </div>
</template>

Custom Display Format

Pass parameter format to custom display format.

Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';

    const defaultValue = new Date(2024, 4, 6, 10, 30, 0);
</script>

<template>
    <DatePicker :defaultValue="defaultValue" format="yyyy年MM月dd日 HH:mm" type="dateTime" />
</template>

Custom Trigger

Version: >=0.34.0

By default we use the Input component as the trigger for the DatePicker component. You can customize this trigger with the #trigger scoped slot.

The custom trigger is a complete customization of the trigger, the default clear button will not take effect, if you need clear function, please customize a clear button that calls onClear from the slot props.

The slot props are value, inputValue, placeholder, disabled, size, inputReadOnly, rangeInputFocus, type, format, multiple, autofocus and componentProps, plus onChange (sets the input text, as typing does), onEnterPress (commits the input text) and onClear (reports a click on the clear button). inputValue is null until the user types; show the formatted value then. The slot props carry no aria-* attributes, so name the custom content yourself.

Code
<script setup lang="ts">
    import { ref } from 'vue';
    import * as dateFns from 'date-fns';
    import { IconChevronDown, IconClose } from '@fibrous/semi-icons-vue';
    import { Button, ButtonGroup, DatePicker, type DatePickerValueType } from '@fibrous/semi-ui-vue';

    const formatToken = 'yyyy-MM-dd';
    const date = ref<DatePickerValueType | null | undefined>(new Date(2024, 4, 6, 10, 30, 0));
</script>

<template>
    <DatePicker v-model="date" :format="formatToken">
        <template #trigger="{ value, placeholder }">
            <!-- The clear button is a sibling of the trigger button: buttons cannot nest -->
            <ButtonGroup theme="light">
                <Button iconPosition="right">
                    <template #icon>
                        <IconChevronDown />
                    </template>
                    {{ value.length ? dateFns.format(value[0], formatToken) : placeholder }}
                </Button>
                <Button v-if="date" aria-label="清除" @click.stop="date = null">
                    <template #icon>
                        <IconClose />
                    </template>
                </Button>
            </ButtonGroup>
        </template>
    </DatePicker>
</template>
Code
<script setup lang="ts">
    import { ref } from 'vue';
    import * as dateFns from 'date-fns';
    import { IconChevronDown, IconClose } from '@fibrous/semi-icons-vue';
    import { Button, ButtonGroup, DatePicker, type DatePickerValueType } from '@fibrous/semi-ui-vue';

    const formatToken = 'yyyy-MM-dd HH:mm:ss';
    const date = ref<DatePickerValueType>();

    function onChange(value: Date | Date[] | undefined) {
        console.log(value);
    }
</script>

<template>
    <DatePicker v-model="date" type="dateTimeRange" @change="onChange">
        <template #trigger="{ value }">
            <!-- The clear button is a sibling of the trigger button: buttons cannot nest -->
            <ButtonGroup theme="light">
                <Button iconPosition="right">
                    <template #icon>
                        <IconChevronDown />
                    </template>
                    {{ value.length ? `${dateFns.format(value[0], formatToken)} ~ ${dateFns.format(value[1], formatToken)}` : '请选择日期时间范围' }}
                </Button>
                <Button v-if="value.length" aria-label="清除" @click.stop="date = undefined">
                    <template #icon>
                        <IconClose />
                    </template>
                </Button>
            </ButtonGroup>
        </template>
    </DatePicker>
</template>

Custom Render Date Content

Version:>=1.4.0

The #date="{ dayNumber, fullDate }" scoped slot.

  • dayNumber: such as 13.
  • fullDate: such as 2020-08-13.
Code
<script setup lang="ts">
    import { DatePicker, Tooltip } from '@fibrous/semi-ui-vue';

    const dateStyle = {
        width: '100%',
        height: '100%',
        border: '1px solid var(--semi-color-primary)',
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center',
    };
</script>

<template>
    <DatePicker>
        <template #date="{ dayNumber }">
            <Tooltip v-if="dayNumber === 1">
                <div :style="dateStyle">{{ dayNumber }}</div>
                <template #content>Always Day 1</template>
            </Tooltip>
            <template v-else>{{ dayNumber }}</template>
        </template>
    </DatePicker>
</template>

Custom Render Date Box

Version:>=1.4.0

The #fullDate="{ dayNumber, fullDate, dayStatus }" scoped slot replaces the whole date box; the box keeps only its base and active class names.

dayStatus is this status of current date box. The included keys are as follows.

type DayStatusType = { isToday?: boolean, isSelected?: boolean, isDisabled?: boolean, isSelectedStart?: boolean, isSelectedEnd?: boolean, isInRange?: boolean, isHover?: boolean, isOffsetRangeStart?: boolean, isOffsetRangeEnd?: boolean, isHoverInOffsetRange?: boolean, }
~
Code
<script setup lang="ts">
    import { DatePicker } from '@fibrous/semi-ui-vue';

    const prefix = 'components-datepicker-demo';
    const dayStyle = {
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        width: '80%',
        height: '80%',
        borderRadius: 'var(--semi-border-radius-circle)',
    };
</script>

<template>
    <DatePicker :style="{ width: '260px' }" type="dateRange">
        <template #fullDate="{ dayNumber, dayStatus }">
            <div
                :class="{
                    [`${prefix}-day-inrange`]: dayStatus.isInRange,
                    [`${prefix}-day-hover`]: dayStatus.isHover,
                    [`${prefix}-day-selected`]: dayStatus.isSelected,
                    [`${prefix}-day-selected-start`]: dayStatus.isSelectedStart,
                    [`${prefix}-day-selected-end`]: dayStatus.isSelectedEnd,
                }"
                :style="dayStyle"
            >
                {{ dayNumber }}
            </div>
        </template>
    </DatePicker>
</template>
.components-datepicker-demo-day-inrange,
.components-datepicker-demo-day-hover {
    background: var(--semi-color-primary-light-hover);
}

.components-datepicker-demo-day-selected,
.components-datepicker-demo-day-selected-start,
.components-datepicker-demo-day-selected-end {
    color: var(--semi-color-bg-2);
    background: var(--semi-color-primary);
}

API Reference

Props

PropertyDescriptionTypeDefault
modelValueThe bound value: a Date, a timestamp or a string in format, and an array for range and multiple. null is a controlled empty value; undefined leaves the picker uncontrolled.ValueType | nullundefined
defaultValueThe initial value when uncontrolled.ValueTypesemiGlobalDefault("DatePicker", "defaultValue")
openControls whether the panel is open; use it with v-model:open.booleanundefined
defaultOpenWhether the panel is open initially.booleansemiDefault("DatePicker", "defaultOpen", false)
typeType: date, dateRange, dateTime, dateTimeRange, month, monthRange or year.TypesemiDefault("DatePicker", "type", "date")
formatFormat of the text in the input; the default depends on type. A format without time tokens turns dateTime into date and dateTimeRange into dateRange.stringsemiGlobalDefault("DatePicker", "format")
defaultPickerValueThe date the panel shows while there is no value; for dateTime types it is also the default time at the bottom. Compared by content: when the content changes the panel moves back to it, so passing new Date() on every render counts as a change.ValueTypesemiGlobalDefault("DatePicker", "defaultPickerValue")
multipleWhether several dates can be chosen; only for type date.booleansemiDefault("DatePicker", "multiple", false)
maxThe number of dates multiple allows; unlimited when omitted.numbersemiGlobalDefault("DatePicker", "max")
needConfirmWhether the value is written only after a confirmation; for dateTime and dateTimeRange only.booleansemiDefault("DatePicker", "needConfirm", false)
disabledWhether the picker is disabled.booleansemiDefault("DatePicker", "disabled", false)
disabledDateReturns true to disable a date. The second argument carries rangeStart, rangeEnd and rangeInputFocus. When type is year, it is called with January 1 of each year, and returning true disables that year.DisabledDateTypeundefined
disabledTimeReturns disabledHours, disabledMinutes and disabledSeconds for the current date and panel position.DisabledTimeTypeundefined
disabledTimePickerWhether the time selection is disabled; for dateTime and dateTimeRange only.booleansemiDefault("DatePicker", "disabledTimePicker", false)
hideDisabledOptionsHides the times that are disabled.booleansemiDefault("DatePicker", "hideDisabledOptions", false)
startDateOffsetFor dateRange, the start date of a range chosen with one click.DateOffsetTypeundefined
endDateOffsetFor dateRange, the end date of a range chosen with one click.DateOffsetTypeundefined
placeholderPlaceholder of the input; an array for range types. Defaults to the text of the locale for type.string | string[]semiGlobalDefault("DatePicker", "placeholder")
rangeSeparatorSeparator between the dates of a range input, also used to parse the text. Use the rangeSeparator slot to change only how it is shown.stringTypesemiDefault("DatePicker", "rangeSeparator", strings.DEFAULT_SEPARATOR_RANGE)
sizeSize of the input: small, default or large.SizesemiDefault("DatePicker", "size", "default")
densitySize of the panel: default or compact.DensityTypesemiDefault("DatePicker", "density", "default")
borderlessRemoves the border of the input.booleansemiDefault("DatePicker", "borderless", false)
showClearWhether the clear button is shown.booleansemiDefault("DatePicker", "showClear", true)
inputReadOnlyWhether the input is read-only.booleansemiDefault("DatePicker", "inputReadOnly", false)
inputStyleStyle of the root element of the input.StyleValuesemiGlobalDefault("DatePicker", "inputStyle")
insetInputMoves the inputs into the panel; pass an object to set the placeholders of the inputs.boolean | InsetInputPropssemiDefault("DatePicker", "insetInput", false)
insetLabelIdThe id of the inset label element.stringundefined
validateStatusValidation status: default, error or warning. Only affects the style."default" | "error" | "warning" | "success"semiGlobalDefault("DatePicker", "validateStatus")
autofocusFocuses the input on mount, which opens the panel.booleansemiDefault("DatePicker", "autofocus", false)
preventScrollWhether focusing the input prevents the browser from scrolling to it.booleansemiGlobalDefault("DatePicker", "preventScroll")
weekStartsOnThe first day of the week: 0 is Sunday, 1 is Monday, and so on.WeekStartNumbersemiDefault("DatePicker", "weekStartsOn", numbers.WEEK_START_ON)
startYearFirst year of the year wheel. Defaults to 100 years before this year.numbersemiGlobalDefault("DatePicker", "startYear")
endYearLast year of the year wheel, which must be after the start year. Defaults to 100 years after this year.numbersemiGlobalDefault("DatePicker", "endYear")
autoSwitchDateSwitches the selected date automatically when the year or month is changed with the arrow buttons or the dropdown. Only for the date type.booleansemiDefault("DatePicker", "autoSwitchDate", true)
syncSwitchMonthSwitches both panels of a range together.booleansemiDefault("DatePicker", "syncSwitchMonth", false)
presetsShortcuts for dates and times. An item, and its start or end, can be a function that is called when the panel renders and when it is clicked.PresetsTypesemiGlobalDefault("DatePicker", "presets")
presetPositionPosition of the presets: left, right, top or bottom."top" | "bottom" | "left" | "right"semiDefault("DatePicker", "presetPosition", "bottom")
timePickerOptsOptions for the time panel: use12Hours, hourStep, minuteStep, secondStep, defaultIsAM and scrollItemProps. The panel owns the format, the value and the disabled times.TypePartial<Pick<ComboboxProps, "use12Hours" | "hourStep" | "minuteStep" | "secondStep" | "scrollItemProps" | "defaultIsAM">>semiGlobalDefault("DatePicker", "timePickerOpts")
yearAndMonthOptsOptions for the year and month columns: cycled, mode, motion and transform. The panel owns the list and the selection.TypePartial<Pick<ScrollItemProps<Item>, "motion" | "mode" | "cycled" | "transform">>semiGlobalDefault("DatePicker", "yearAndMonthOpts")
timeZoneTime zone; a number is the offset from UTC in hours. Falls back to the timeZone of ConfigProvider, then to the global default.string | numberundefined
motionWhether the panel animates when it opens.booleansemiDefault("DatePicker", "motion", true)
autoAdjustOverflowWhether the panel adjusts its direction when it is clipped.booleansemiDefault("DatePicker", "autoAdjustOverflow", true)
positionPosition of the panel. Defaults to bottomLeft (bottomRight in RTL), and to leftTopOver with insetInput.Type"top" | "bottom" | "left" | "right" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver" | "leftBottomOver" | "rightBottomOver"semiGlobalDefault("DatePicker", "position")
spacingDistance between the panel and the trigger. 1 for an insetInput panel over the trigger, otherwise the Popover spacing.numbersemiGlobalDefault("DatePicker", "spacing")
stopPropagationWhether click events on the panel stop propagating.string | booleansemiDefault("DatePicker", "stopPropagation", true)
dropdownClassNameClass name of the panel.stringsemiGlobalDefault("DatePicker", "dropdownClassName")
dropdownStyleInline style of the panel.StyleValuesemiGlobalDefault("DatePicker", "dropdownStyle")

Events

EventDescriptionCallback parameters
update:modelValueEmitted when the value changes, for v-model. It is undefined when a single value is cleared and [] for range and multiple.[value: Date | Date[] | undefined]
changeEmitted when the value changes, with the date and the date string; both are arrays for range and multiple. A range type emits it only after both dates are chosen. Shadows the native change event bubbling from the root.[date: Date | Date[] | undefined, dateString: string | string[]]
update:openEmitted when the panel opens or closes, for v-model:open.[open: boolean]
openChangeEmitted when the panel opens or closes, together with update:open.[open: boolean]
focusEmitted when an input gets focus, or when a click or key press on the trigger focuses the range start. rangeType is set for range inputs only, and moving between them does not emit again. Shadows the native focus event.Type[event: MouseEvent | FocusEvent | KeyboardEvent, rangeType?: RangeInput | undefined]
blurEmitted when the panel closes. The argument is the mousedown that closed it from outside; other ways to close, such as confirming, choosing a date or Esc, pass none. Shadows the native blur event.[event?: MouseEvent | undefined]
clearEmitted when the clear button is clicked.[event: MouseEvent]
cancelEmitted when the selection is cancelled, with the last confirmed value. Only with needConfirm.[date: Date | Date[], dateString: string | string[]]
confirmEmitted when the selection is confirmed, with the selected value. Only with needConfirm.[date: Date | Date[], dateString: string | string[]]
panelChangeEmitted when the year or month of the panel changes.[date: Date | Date[], dateString: string | string[]]
presetClickEmitted when a preset button is clicked; the second argument is the native MouseEvent.[item: PresetType, event: MouseEvent]
clickOutSideEmitted when the panel is open and the user presses outside the panel and the trigger, with the native mousedown event.[event: MouseEvent]

Slots

SlotDescriptionScope parameters
triggerReplaces the trigger. It receives value, inputValue, placeholder, disabled, size, inputReadOnly, rangeInputFocus, type, format, multiple, autofocus and componentProps, plus onChange (sets the input text), onEnterPress (commits it) and onClear. The default clear button no longer applies.DatePickerTriggerSlotProps
dateContent of a day cell, with dayNumber and fullDate (yyyy-MM-dd).DatePickerDateSlotProps
fullDateReplaces the whole day cell, with dayNumber, fullDate and dayStatus. The cell keeps only its base and active classes.DatePickerFullDateSlotProps
topSlotExtra area at the top of the panel.any
bottomSlotExtra area at the bottom of the panel.any
leftSlotExtra area at the left of the panel.any
rightSlotExtra area at the right of the panel.any
prefixPrefix of the input.any
insetLabelInset label of the input.any
clearIconCustom clear icon, used when showClear is true.any
rangeSeparatorHow the separator between the range inputs is shown. It does not affect parsing.any

Exposes

NameDescriptionType
closeCloses the panel. A controlled open wins.Type() => void
focusFocuses the input. A range focuses its start input unless rangeEnd is given. With insetInput the focus goes to the input in the panel.Type(focusType?: RangeInput | undefined) => void
blurBlurs the input.Type() => void

modelValue with update:modelValue is v-model, and open with update:open is v-model:open. autofocus is lowercase; triggerRender, renderDate, renderFullDate, rangeSeparatorNode and the other ReactNode props are slots.

Undeclared attributes such as class, style, id, title, data-* and aria-label land on the root element, which is role="group" when it has an aria-label. Where aria-labelledby, aria-describedby, aria-errormessage, aria-invalid and aria-required land:

  • A single input: all of them land on the input
  • A range type: the root element is role="group" and takes aria-labelledby; the other four land on both inputs
  • #trigger content without a focusable element: aria-labelledby, aria-describedby, aria-errormessage and aria-invalid land on the wrapper with the role button; aria-required is not forwarded
  • #trigger content with its own focusable element: none of them is forwarded, so set them on the slot content

change, focus and blur shadow the native events of the same name bubbling from the root. A DatePicker deactivated inside <KeepAlive> closes its panel and emits only update:open and openChange.

Methods

A template ref exposes open(), close(), focus(rangeEnd?) and blur(). focus focuses the input; a range focuses its start input unless rangeEnd is given, and with insetInput the focus goes to the input in the panel. blur blurs the input. A controlled open wins: open() and close() do not change the visibility of the panel then.

Code
<script setup lang="ts">
    import { useTemplateRef } from 'vue';
    import { Button, DatePicker, Space, type DatePickerHandle } from '@fibrous/semi-ui-vue';

    const picker = useTemplateRef<DatePickerHandle>('picker');

    const handleClickOutside = () => {
        console.log('click outside');
    };
</script>

<template>
    <Space align="start" vertical>
        <Space>
            <Button @click="picker?.open()">open</Button>
            <Button @click="picker?.close()">close</Button>
            <Button @click="picker?.focus()">focus</Button>
            <Button @click="picker?.blur()">blur</Button>
        </Space>
        <div>
            <DatePicker ref="picker" type="dateTime" @clickOutSide="handleClickOutside" />
        </div>
    </Space>
</template>

Interface Define

type DatePickerBaseValueType = string | number | Date;
type DatePickerValueType = DatePickerBaseValueType | DatePickerBaseValueType[];
type DatePickerType = 'date' | 'dateRange' | 'dateTime' | 'dateTimeRange' | 'month' | 'monthRange' | 'year';
type DatePickerRangeInput = 'rangeStart' | 'rangeEnd';
type DatePickerTriggerSlotProps = {
    value: Date[];
    inputValue: string | null;
    placeholder: string | string[];
    disabled: boolean;
    size: InputSize;
    inputReadOnly: boolean;
    rangeInputFocus: DatePickerRangeInput | false | undefined;
    type: DatePickerType;
    format?: string;
    multiple: boolean;
    autofocus: boolean;
    componentProps: DatePickerProps;
    onChange: (inputValue: string) => void;
    onEnterPress: (inputValue: string) => void;
    onClear: (event: MouseEvent) => void;
};

Accessibility

ARIA

  • The input has the role combobox with aria-haspopup="dialog", an aria-expanded that follows the panel, and aria-controls pointing at the panel; both inputs of a range do
  • A single input is named Choose date while no date is selected and Change date once one is (an aria-labelledby you pass wins)
  • When the content of a custom trigger (triggerRender in React, the #trigger slot in Vue) has no focusable element, the wrapper is the focus target with the role button, named as above
  • The role of the month in the date panel is grid, named by the year and month title at the top of the panel; the role of the week is set to row, and the date cell is set to gridcell
  • The year and month scroll columns are listbox lists named "year" and "month"
  • aria-disabled is true for the corresponding option when date and time are disabled
  • With multiple or range selection, aria-multiselectable of month is true, and aria-selected of date grid is true when selected
  • Some decorative icons in the panel, their aria-hidden is true

Keyboard and Focus

  • Down Arrow in the input opens the panel; once the panel is open, Down Arrow moves focus into it
  • The date grid is one Tab stop: the arrow keys, Home, End, PageUp and PageDown (by year with Shift) move the active date, and Enter or Space picks it
  • The date and time switches at the bottom of a dateTime panel are buttons that Enter or Space activates
  • With a range value, Tab reaches the clear button after the end input, and Enter or Space clears the range
  • Esc closes the panel; focus inside the panel returns to the input, or to the custom trigger when there is one
  • When the content of a custom trigger has no focusable element, Tab reaches the wrapper, and Enter, Space or Down Arrow opens the panel

Date and Time Format

Adopted in the semi-ui component library date-fns v4 As a date and time engine, formatting token means the following:

  • "y": Year
  • "M": month
  • "d": day
  • "H": hours
  • "h": hours (12h)
  • "m": minutes
  • "s": seconds

The following uses new Date('2023-12-09 08:08:00') or [new Date('2023-12-09 08:08:00'), new Date('2023-12-10 10 :08:00')] as value to explain the impact of different types and different format values on the displayed value:

typeformatdisplay value
dateyyyy-MM-dd2023-12-09
dateTimeyyyy-MM-dd HH:mm:ss2023-12-09 08:08:00
monthyyyy-MM2023-12
yearyyyy2023
dateRangeyyyy-MM-dd2023-12-09 ~ 2023-12-10
dateTimeRangeyyyy-MM-dd HH:mm:ss2023-12-09 08:08 ~ 2023-12-10 10:08

Multiple dates or times are used by default "," (English comma) separated.

More token available Date-fns official website

Content Guidelines

  • Date picker is recommended to be used with tags
  • Use concise labels to indicate what the date selection refers to
  • Please refer to Date and Time

Design Tokens

These are the component's internal Sass variables and cannot be overridden. To customize styles, override the --semi-* CSS variables (see the Design Token page) or write unlayered CSS rules.
Sass variableValueUsage
$width-datepicker_day36px日期格子及星期标题尺寸
$width-datepicker_day_main32px日期格子内容尺寸
$width-datepicker_month$width-datepicker_day * 7日期视图单月面板宽度
$width-datepicker_nav32px顶部导航栏高度
$height-datepicker_switch54px日期时间切换高度
$height-datepicker_timeType_yamcalc(100% - 54px)时间面板高度
$height-datepicker_timeType_tpkcalc(100% - 54px)时间面板高度
$height-datepicker_panel_yam_scrolllist266px年月选择列表滚动区域高度
$width-datepicker_monthPanel_max284px年月选择器最大宽度
$width-datepicker_monthRangePanel_max384px年月选择器最大宽度
$height-datepicker_timepicker_header_min24px年月选择面板顶部导航栏最小高度
$width-datepicker_navigation_button_min32px顶部导航栏按钮最小宽度
$height-datepicker_yamShowing_min378px日期时间选择器菜单最小高度
$width-datepicker_yamShowing_min284px选择器菜单最小宽度
$height-datepicker_dateType_yamShowing_min325px日期选择器菜单最小高度
$width-datepicker_panel_yam_scrolllist_li_min64px年月、时间滚动菜单项最小高度
$width-datepicker_presetPanel_left_and_right200px左右方位快捷选择面板宽度
$height-datepicker_presetPanel_top_and_bottom_max100px上下方位快捷选择面板最大高度
$width-datepicker_presetPanel_scroll_bar15px快捷选择面板scrollbar宽度
$width-datepicker-border$border-thickness-control年月选择面板顶部导航栏底部分割线宽度
$width-datepicker_yam_header-borderRadiusvar(--semi-border-radius-medium)年月选择面板顶部导航栏圆角
$width-datepicker_day_main-borderRadiusvar(--semi-border-radius-small)日期格子圆角
$width-datepicker_slot-border1px日期星期分割线宽度
$width-datepicker_range_input-border$border-thickness-control-focus
$width-datepicker_day_main-border1px
$height-datepicker_timeType_insetInput_yam100%时间面板高度 - 内嵌输入框
$height-datepicker_timeType_insetInput_tpk100%时间面板高度 - 内嵌输入框
$width-datepicker_insetInput_date_type_wrapper284px日期类型内嵌输入框宽度
$width-datepicker_insetInput_date_range_type_wrapper$width-datepicker_insetInput_date_type_wrapper * 2范围选择内嵌输入框宽度
$width-datepicker_insetInput_month_type_wrapper165px月份类型内嵌输入框宽度
$width-datepicker_insetInput_month_range_type_wrapper331px年月范围类型内嵌输入框宽度
$height-datepicker_insetInput_separator32px
$height-datepicker_month_grid_yearType_insetInput317px
$height-datepicker_month_grid_timeType_insetInput317px
$width-datepicker_range_trigger-border0px触发器边框宽度
$spacing-datepicker_day-marginX($width-datepicker_day - $width-datepicker_day_main) * 0.5日期格子水平外边距
$spacing-datepicker_yam_header-paddingX$spacing-base年月选择面板顶部导航栏水平内边距
$spacing-datepicker_yam_header-paddingY$spacing-base-tight年月选择面板顶部导航栏垂直内边距
$spacing-datepicker_scrolllist_header-padding$spacing-base时间选择 header 内边距
$spacing-datepicker_scrolllist_body-padding0时间选择滚动菜单内边距
$spacing-datepicker_footer-paddingTop10px确认选择 footer 顶部内边距
$spacing-datepicker_footer-paddingBottom10px确认选择 footer 底部内边距
$spacing-datepicker_footer-paddingRight8px确认选择 footer 右侧内边距
$spacing-datepicker_footer_cancel_button-marginRight12px确认选择 footer 取消按钮右外边距
$spacing-datepicker_footer_confirm_button-marginRight8px确认选择 footer 确认按钮右外边距
$spacing-datepicker_navigation-paddingY$spacing-base-tight年月切换 header 垂直内边距
$spacing-datepicker_navigation-paddingX$spacing-base年月切换 header 水平内边距
$spacing-datepicker_month-padding$spacing-base
$spacing-datepicker_switch_datetime-paddingTop$spacing-base日期时间切换顶部内边距
$spacing-datepicker_switch_datetime-paddingBottom$spacing-base日期时间切换底部内边距
$spacing-datepicker_switch_text-paddingLeft$spacing-tight日期时间切换左侧内边距
$spacing-datepicker_quick_control_header-paddingTop18px快捷预设面板标题区域上内边距
$spacing-datepicker_quick_control_top_and_bottom_content-paddingX$spacing-base-loose上下方位快捷操作面板, 左右内边距,默认20px
$spacing-datepicker_quick_control_content-paddingX12px快捷面板内容,左右内边距
$spacing-datepicker_quick_control_content-marginTop14px快捷面板内容,上边距
$spacing-datepicker_quick_control_item-margin$spacing-tight快捷操作面板按钮间距
$spacing-datepicker_range_input-paddingX8px
$spacing-datepicker_range_input_inputWrapper_input-paddingY2px
$spacing-datepicker_range_input_inputWrapper_input-paddingX4px
$spacing-datepicker_range_input_prefix-paddingLeft12px
$spacing-datepicker_range_input_prefix-paddingRight8px
$spacing-datepicker_range_input_suffix-paddingLeft8px
$spacing-datepicker_range_input_suffix-paddingRight12px
$spacing-datepicker_range_input_clearbtn-paddingLeft8px
$spacing-datepicker_range_input_clearbtn-paddingRight12px
$spacing-datepicker_navigation_insetInput-paddingY8px年月切换 header 垂直内边距 - 内嵌输入框
$spacing-datepicker_insetInput_wrapper-margin8px
$spacing-datepicker_insetInput_wrapper-paddingY12px
$spacing-datepicker_insetInput_wrapper-paddingX16px
$spacing-datepicker_insetInput_wrapper-paddingBottom0
$spacing-datepicker_insetInput_separator-paddingY0
$spacing-datepicker_insetInput_separator-paddingX4px
$color-datepicker_header-bg-defaultvar(--semi-color-bg-3)日期选择器 header 背景颜色
$color-datepicker_list-bg-defaultvar(--semi-color-bg-3)日期选择器滚动列表背景颜色
$color-datepicker_border-bg-defaultvar(--semi-color-border)日期选择器描边颜色
$color-datepicker_footer-bg-defaultvar(--semi-color-fill-0)日期选择器确认选择 footer 背景颜色
$color-datepicker_quick-bg-defaulttransparent日期选择器快捷操作背景颜色
$color-datepicker_quick_button-text-defaultvar(--semi-color-primary)日期选择器快捷操作按钮文字颜色
$color-datepicker_day-text-defaultvar(--semi-color-text-2)星期标题及日期时间切换按钮文字颜色 - 默认
$color-datepicker_day-text-activevar(--semi-color-text-0)日期时间切换文字颜色 - 选中
$color-datepicker_date-text-defaultvar(--semi-color-text-0)日期格子文字颜色 - 默认
$color-datepicker_date-bg-defaultvar(--semi-color-fill-0)日期格子背景颜色 - 默认
$color-datepicker_date-bg-hovervar(--semi-color-fill-0)日期格子背景颜色 - 悬浮
$color-datepicker_date-bg-activevar(--semi-color-fill-1)日期格子背景颜色 - 按下
$color-datepicker_date_selected-text-defaultvar(--semi-color-white)日期格子文字颜色 - 选中
$color-datepicker_date_selected-bg-defaultvar(--semi-color-primary)日期格子背景颜色 - 选中
$color-datepicker_date_disabled-text-defaultvar(--semi-color-disabled-text)禁用日期格子文字颜色
$color-datepicker_date_disabled-bg-defaultvar(--semi-color-disabled-fill)禁用日期格子背景颜色
$color-datepicker_date_today-text-defaultvar(--semi-color-primary)今日文字颜色
$color-datepicker_date_today_disabled-text-defaultvar(--semi-color-primary-disabled)今日文字颜色 - 禁用
$color-datepicker_date_inHover-bg-defaultvar(--semi-color-primary-light-default)范围选择日期格子颜色
$color-datepicker_date_inRangeHover-bg-defaultvar(--semi-color-fill-0)范围选择时悬停路径内的日期背景色
$color-datepicker_date_hoverDay-bg-defaultvar(--semi-color-fill-1)范围选择时日期格子背景色 - 悬停
$color-datepicker_date_selectedRange-bg-hovervar(--semi-color-primary-light-hover)范围选择日期格子颜色 - 悬浮
$color-datepicker_date_hoverday_range-bg-defaultvar(--semi-color-primary-light-active)
$color-datepicker_date_hoverday_around_single_selected-bg-defaultvar(--semi-color-primary-light-active)
$color-datepicker_nav_monthIcon-text-defaultvar(--semi-color-text-0)顶部导航栏年月文字颜色 - 默认
$color-datepicker_navIcon-text-defaultvar(--semi-color-text-2)日期选择器 header 左右箭头颜色
$color-datepicker_input_primary-text-defaultvar(--semi-color-primary)
$color-datepicker_range_input-text-defaultvar(--semi-color-text-2)
$color-datepicker_range_input-bg-defaultvar(--semi-color-fill-0)
$color-datepicker_range_input-bg-hovervar(--semi-color-fill-1)
$color-datepicker_range_input-border-defaulttransparent
$color-datepicker_range_input-border-activevar(--semi-color-focus-border)
$color-datepicker_range_input_warning-border-activevar(--semi-color-warning)
$color-datepicker_range_input_warning-bg-activevar(--semi-color-warning-light-hover)
$color-datepicker_range_input_warning-bg-defaultvar(--semi-color-warning-light-default)
$color-datepicker_range_input_warning-bg-hovervar(--semi-color-warning-light-hover)
$color-datepicker_range_input_warning-border-defaultvar(--semi-color-warning-light-default)
$color-datepicker_range_input_error-border-defaultvar(--semi-color-danger-light-default)
$color-datepicker_range_input_error-bg-hovervar(--semi-color-danger-light-hover)
$color-datepicker_range_input_error-border-activevar(--semi-color-danger)
$color-datepicker_range_input_error-bg-activevar(--semi-color-danger-light-hover)
$color-datepicker_range_input_disabled-text-defaultvar(--semi-color-disabled-text)
$color-datepicker_range_input_disabled-bg-defaultvar(--semi-color-disabled-fill)
$color-datepicker_range_input_disabled-bg-hovervar(--semi-color-disabled-fill)
$color-datepicker_range_input_clearbtn-icon-hovervar(--semi-color-primary-hover)
$color-datepicker_range_input_inputWrapper-border-defaulttransparent
$color-datepicker_range_input_inputWrapper-bg-defaulttransparent
$color-datepicker_range_input_inputWrapper-bg-focusvar(--semi-color-fill-1)
$color-datepicker_range_input_separator-text-activevar(--semi-color-text-0)
$color-datepicker_day_main-bordervar(--semi-color-primary-active)
$color-datepicker_insetInput_separatorvar(--semi-color-text-3)
$color-datepicker_range_trigger-bordertransparent范围日期选择模式触发器边框颜色
$color-datepicker_range_trigger-border-hovertransparent范围日期选择模式触发器边框颜色 - 悬浮
$color-datepicker_range_trigger-border-activetransparent范围日期选择模式触发器边框颜色 - 激活
$color-datepicker_range_trigger-border-focustransparent范围日期选择模式触发器边框颜色 - 聚焦
$font-datepicker_range_input_prefix_suffix_clearbtn-fontWeight600
$font-datepicker_preset_header-fontWeight600
$font-datepicker_range_input_prefix_suffix_clearbtn-fontSize14px
$font-datepicker_range_input_prefix_suffix_clearbtn-lineHeight20px
$font-datepicker_range_input_large-fontSize16px
$spacing-datepicker_month_compact-padding10px
$width-datepicker_day_compact28px
$width-datepicker_day_main_compact24px
$width-datepicker_day_compact-borderRadius4px
$width-datepicker_month_compact$width-datepicker_day_compact * 7 + $spacing-datepicker_month_compact-padding * 2
$width-datepicker_nav_compact24px
$width-datepicker_panel_compact216px
$height-datepicker_switch_compact32px
$height-datepicker_tpk_compact256px
$height-datepicker_yam_panel_compact256px
$height-datepicker_yam_li_compact32px
$height-datepicker_yam_panel_header_compact48px
$radius-datepicker_range_input_inputWrappervar(--semi-border-radius-small)
$height-datepicker_range_input-default32px
$height-datepicker_range_input-small24px
$height-datepicker_range_input-large40px
$width-datepicker_insetInput_date_type_wrapper_compact216px
$width-datepicker_insetInput_date_range_type_wrapper_compact$width-datepicker_insetInput_date_type_wrapper_compact * 2
$width-datepicker_insetInput_month_type_wrapper_compact195px
$height-datepicker_insetInput_tpk_compact100%
$height-datepicker_timeType_insetInput_yam_compact100%
$height-datepicker_insetInput_wrapper_compact28px
$lineHeight-datepicker_compact20px
$lineHeight-datepicker_weekday_item_compact28px
$height-datepicker_insetInput_compact26px
$fontSize-datepicker_insetInput_compact-fontSize12px
$spacing-datepicker_switch_compact-padding6px
$spacing-datepicker_day_compact-margin($width-datepicker_day_compact - $width-datepicker_day_main_compact) * 0.5
$spacing-datepicker_weeks_compact-padding10px
$spacing-datepicker_weeks_compact-paddingTop$spacing-tight - 2px
$spacing-datepicker_weekday_compact-paddingLeft10px
$spacing-datepicker_weekday_compact-paddingRight10px
$spacing-datepicker_weekday_compact-paddingBottom$spacing-tight
$spacing-datepicker_nav_compact-padding12px
$spacing-datepicker_yam_panel_header_compact-padding12px
$spacing-datepicker_footer_compact-paddintTop10px
$spacing-datepicker_footer_compact-paddintBottom10px
$spacing-datepicker_footer_compact-paddintRight8px
$spacing-datepicker_scrolllist_shade_pre_compact-marginTop-17px
$spacing-datepicker_scrolllist_shade_post_compact-marginTop17px
$spacing-datepicker_insetInput_wrapper_compact-margin4px
$spacing-datepicker_insetInput_wrapper_compact-paddingY8px
$spacing-datepicker_insetInput_wrapper_compact-paddingX8px
$spacing-datepicker_insetInput_wrapper_compact-paddingBottom0
$spacing-datepicker_insetInput_wrapper_rangeType_compact-paddingTop0
$spacing-datepicker_quick_control_header_compact-paddingTop16pxcompact, 快捷面板标题,上内边距
$spacing-datepicker_quick_control_content_compact-marginTop12pxcompact, 快捷面板内容,上边距
$spacing-datepicker_quick_control_left_and_right_content_compact-paddingX12pxcompact,左右方位,快捷面板内容,左右内边距
$spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX10pxcompact,上下方位,快捷面板内容,左右内边距
$radius-datepicker_range_inputvar(--semi-border-radius-small)
$transition-datepicker_range_inputbackground-color 0.16s ease-in-out
$width-datepicker_presetPanel_left_and_right_content$width-datepicker_presetPanel_left_and_right - $spacing-datepicker_quick_control_content-paddingX * 2左右方位快捷选择面板,内容宽度
$width-datepicker_presetPanel_top_and_bottom_content_date$width-datepicker_day * 7 + $spacing-datepicker_month-padding * 2 - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2date/dateTime下, 上下方位快捷选择面板内容宽度, 默认(284 - 40)px
$width-datepicker_presetPanel_top_and_bottom_content_range($width-datepicker_day * 7 + $spacing-datepicker_month-padding * 2) * 2 - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2dateRange/dateTimeRange下, 上下方位快捷选择内容面板宽度,默认528px
$width-datepicker_presetPanel_top_and_bottom_content_month165px - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2month下,上下方位快捷选择内容面板宽度, 默认154px
$height-datepicker_month_max$width-datepicker_day * 7 + 1px年月面板最大高度, 最多6 + 1行,再加上一个border宽度, 默认253px
$height-datepicker_month_max_compact$width-datepicker_day_compact * 7 + $spacing-datepicker_weeks_compact-paddingTop + $spacing-datepicker_weeks_compact-padding + $spacing-datepicker_weekday_compact-paddingBottom年月面板最大高度, 最多6 + 1行,再加上padding,默认220px
$height-datepicker_date_panel$height-datepicker_month_max + $spacing-datepicker_month-padding + $width-datepicker_nav + $spacing-datepicker_navigation-paddingY * 2date/dateRange,面板渲染最大高度,默认325px
$height-datepicker_date_time_panel$height-datepicker_date_panel + $height-datepicker_switch - 1pxdateTime/dateTImeRange 面板渲染最大高度. 默认378px
$height-datepicker_presetPanel_left_and_right_except_content20px + $spacing-datepicker_quick_control_header-paddingTop + $spacing-datepicker_quick_control_content-marginTop除去content以外的高度,默认52px
$width-datepicker_presetPanel_top_and_bottom_content_date_compact$width-datepicker_day_compact * 7 + $spacing-datepicker_weeks_compact-padding * 2 - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2date/dateTime下, 上下方位快捷选择面板内容宽度, 默认(216 - 20)px
$width-datepicker_presetPanel_top_and_bottom_content_range_compact($width-datepicker_day_compact * 7 + $spacing-datepicker_weeks_compact-padding * 2) * 2 - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2dateRange/dateTimeRange下, 上下方位快捷选择内容面板宽度,默认412px
$width-datepicker_presetPanel_top_and_bottom_content_month_compact165px - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2month下,上下方位快捷选择内容面板宽度, 默认174px
$height-datepicker_date_panel_compact$height-datepicker_month_max_compact + $width-datepicker_nav_compact + $spacing-datepicker_nav_compact-paddingcompact,date/dateRange,面板渲染最大高度,默认256px
$height-datepicker_date_time_panel_compact$height-datepicker_date_panel_compact + $height-datepicker_switch_compactcompact,dateTime/dateTImeRange,面板渲染最大高度,默认288px
$height-datepicker_presetPanel_left_and_right_except_content_compact20px + $spacing-datepicker_quick_control_header_compact-paddingTop + $spacing-datepicker_quick_control_content_compact-marginTopcompact,除去content以外的高度,默认48px
$width-datepicker_presetPanel_left_and_right_two_col_button($width-datepicker_presetPanel_left_and_right_content - $spacing-datepicker_quick_control_item-margin) * 0.5左右方位快捷选择面板,固定两列,按钮宽度
$width-datepicker_presetPanel_top_and_bottom_three_col_button($width-datepicker_presetPanel_top_and_bottom_content_date - $spacing-datepicker_quick_control_item-margin * 2) * 0.333上下方位快捷选择面板,固定三列,按钮宽度
$width-datepicker_presetPanel_top_and_bottom_five_col_button($width-datepicker_presetPanel_top_and_bottom_content_range - $spacing-datepicker_quick_control_item-margin * 4) * 0.2上下方位快捷选择面板,固定五列,按钮宽度
$width-datepicker_presetPanel_top_and_bottom_two_col_button($width-datepicker_presetPanel_top_and_bottom_content_month - $spacing-datepicker_quick_control_item-margin) * 0.5上下方位快捷选择面板,固定两列,按钮宽度
$width-datepicker_presetPanel_top_and_bottom_three_col_button_compact($width-datepicker_presetPanel_top_and_bottom_content_date_compact - $spacing-datepicker_quick_control_item-margin * 2) * 0.333上下方位快捷选择面板,固定三列,按钮宽度
$width-datepicker_presetPanel_top_and_bottom_five_col_button_compact($width-datepicker_presetPanel_top_and_bottom_content_range_compact - $spacing-datepicker_quick_control_item-margin * 4) * 0.2上下方位快捷选择面板,固定五列,按钮宽度
$width-datepicker_presetPanel_top_and_bottom_two_col_button_compact($width-datepicker_presetPanel_top_and_bottom_content_month_compact - $spacing-datepicker_quick_control_item-margin) * 0.5上下方位快捷选择面板,固定两列,按钮宽度
$height-datepicker_inset_input32px + $spacing-datepicker_insetInput_wrapper-paddingY默认尺寸,insetInput高度
$height-datepicker_preset_panel_inset_input$height-datepicker_month_max + $spacing-datepicker_month-padding + $width-datepicker_nav + $spacing-datepicker_navigation_insetInput-paddingY * 2 + $height-datepicker_inset_inputinset_input下,非month面板渲染最大高度,默认361px
$height-datepicker_inset_input_compact28px + $spacing-datepicker_insetInput_wrapper_compact-paddingYcompact,insetInput高度, 默认36px
$height-datepicker_preset_panel_inset_input_compact$height-datepicker_month_max_compact + $width-datepicker_nav_compact + $spacing-datepicker_insetInput_wrapper_compact-paddingY * 2 + $height-datepicker_inset_input_compactinset_input下,非month面板渲染最大高度,默认296px

FAQ

  • Date time picker, when you choose time, minute and second, you don't want to scroll infinitely. How to achieve the effect?
    Starting from version V2.22.0, we changed the default mode of ScrollItem in TimePicker from wheel to normal. If you want to apply the infinite scrolling effect again, you can control this behavior through a specific switch in timePickerOpts, that is:

    :timePickerOpts="{ scrollItemProps: { mode: 'wheel', cycled: true } }".

  • How to set the default display time when the panel is opened?
    You can use the defaultPickerValue property.

  • Date time selection, range date selection, after inputting some dates, the panel does not echo the date?

    The input box needs to be entered completely before it is showed to the panel. For example, for dateTime type, the full requested date and time have been entered. For dateRange type, full requires start and end dates to be entered.

  • What is the displayed time at the bottom of the date time selection panel?

    When no time is selected, it is the value of the time in defaultPickerValue, if not set it is the time when the panel was opened. After selecting a time, it is the selected time.

    Since it has two hidden meanings in design, which may lead to ambiguity, it is recommended to use inline styles and open them through insetInput. It is recommended to read the relevant Documentation before use.

    The time at the bottom of the date time selection panel