Demos
How to import
import { DatePicker } from '@fibrous/semi-ui-react';
Basic Use
Code
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return <DatePicker onChange={(_date, dateString) => console.log(dateString)} />;
}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
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return (
<div>
<DatePicker type="dateTime" density="compact" />
<br />
<br />
<DatePicker type="dateRange" density="compact" style={{ width: 260 }} />
</div>
);
}Multiple Date Selection
Set Multiple to true, can choose multiple dates.
Code
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return <DatePicker multiple style={{ width: 240 }} />;
}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
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return (
<>
<h4>默认日期与时间选择</h4>
<DatePicker type="dateTime" />
<br />
<br />
<h4>开启时间列表无限循环</h4>
<DatePicker
type="dateTime"
timePickerOpts={{
scrollItemProps: { mode: 'wheel', cycled: true },
}}
/>
</>
);
}Date Range Selection
Set type to dateRange, can choose the date range.
Code
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return <DatePicker type="dateRange" style={{ width: 260 }} onChange={console.log} />;
}Date Time Range Selection
Set type to dateTimeRange, can choose the date range and choose time;
Code
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return (
<>
<DatePicker type="dateTimeRange" style={{ width: 400, marginBottom: 8 }} onChange={console.log} />
<DatePicker type="dateTimeRange" style={{ width: 400 }} defaultPickerValue={[new Date('2022-08-08 00:00'), new Date('2022-08-09 12:00')]} onChange={console.log} />
</>
);
}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
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return (
<div>
<DatePicker type="date" insetInput />
<br />
<br />
<DatePicker type="dateTime" insetInput />
<br />
<br />
<DatePicker type="dateRange" insetInput style={{ width: 260 }} />
<br />
<br />
<DatePicker type="dateTimeRange" insetInput style={{ width: 400 }} />
<br />
<br />
<DatePicker type="month" placeholder="请选择年月" insetInput style={{ width: 140 }} />
<br />
<br />
<DatePicker type="monthRange" placeholder="请选择年月范围" insetInput style={{ width: 200 }} />
<br />
<br />
<DatePicker type="date" position="bottomLeft" insetInput />
<br />
<br />
<DatePicker type="dateTime" format="yyyy-MM-dd HH:mm" insetInput />
</div>
);
}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
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return <DatePicker syncSwitchMonth type="dateTimeRange" style={{ width: 400 }} />;
}Panel Change Callback
version:>=1.28.0
onPanelChange will be called when the month or year of the panel is changed.
Code
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return <DatePicker syncSwitchMonth type="dateTimeRange" style={{ width: 400 }} onPanelChange={(date, dateString) => console.log(date, dateString)} />;
}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
import * as dateFns from 'date-fns';
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
const handleChange = (date: Date | Date[]) => {
console.log('date changed', date);
};
return (
<div>
<h4>选择自然周</h4>
<DatePicker style={{ width: 260 }} type="dateRange" weekStartsOn={1} startDateOffset={(date) => dateFns.startOfWeek(date, { weekStartsOn: 1 })} endDateOffset={(date) => dateFns.endOfWeek(date, { weekStartsOn: 1 })} onChange={handleChange} />
<br />
<br />
<h4>选择双周</h4>
<DatePicker style={{ width: 260 }} type="dateRange" weekStartsOn={1} startDateOffset={(date) => dateFns.startOfWeek(date, { weekStartsOn: 1 })} endDateOffset={(date) => dateFns.add(dateFns.endOfWeek(date, { weekStartsOn: 1 }), { days: 7 })} onChange={handleChange} />
<br />
<br />
<h4>选择当前日和后6日</h4>
<DatePicker style={{ width: 260 }} type="dateRange" weekStartsOn={1} endDateOffset={(date) => dateFns.add(date, { days: 6 })} onChange={handleChange} />
<br />
<br />
</div>
);
}Selection
Version: > = 0.21.0
Set type to month, can make year-to-month selection.
Code
import { DatePicker } from '@fibrous/semi-ui-react';
const defaultValue = new Date(2019, 6, 23, 12);
export default function DatePickerDemo() {
return <DatePicker defaultValue={defaultValue} type="month" style={{ width: 140 }} />;
}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
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return <DatePicker type="monthRange" style={{ width: 200 }} />;
}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
import { DatePicker } from '@fibrous/semi-ui-react';
const defaultValue = new Date(2019, 6, 23, 12);
export default function DatePickerDemo() {
return <DatePicker defaultValue={defaultValue} type="year" style={{ width: 140 }} />;
}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 callbacks of the "onConfirm" and "onCancel" buttons are supported.
The following example binds three callbacks: onChange, onConfirm and onCancel, 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
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return (
<DatePicker
type="dateTime"
needConfirm
onConfirm={(...args) => {
console.log('Confirmed: ', ...args);
}}
onCancel={(...args) => {
console.log('Canceled: ', ...args);
}}
onChange={(...args) => {
console.log('Changed: ', ...args);
}}
/>
);
}Date and Time Selection with Shortcuts
Pass parameter Presets to set shortcuts for date selection.
Code
import { DatePicker } from '@fibrous/semi-ui-react';
const presets = [
{
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),
}),
];
export default function DatePickerDemo() {
return <DatePicker type="dateTime" presets={presets} presetPosition="left" />;
}Render TopSlot/BottomSlot
With topSlot and bottomSlot, you can customize the rendering of the top and bottom extra areas. With leftSlot and rightSlot, you can customize the rendering of the left and right extra areas (since v2.65.0).
Code
import { useState, type CSSProperties } from 'react';
import { IconBulb } from '@fibrous/semi-icons-react';
import { DatePicker, Typography, Tabs, TabPane, Space } from '@fibrous/semi-ui-react';
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;
interface SlotProps {
style?: CSSProperties;
}
interface TopSlotProps extends SlotProps {
activeKey: string;
onChange: (activeKey: string) => void;
}
function TopSlot({ style, activeKey, onChange }: TopSlotProps) {
return (
<Tabs size="small" onChange={onChange} activeKey={activeKey} style={{ padding: '12px 20px 0', ...style }}>
<TabPane tab="UED 排期" itemKey="1" />
<TabPane tab="测试排期" itemKey="2" />
</Tabs>
);
}
function BottomSlot({ style }: SlotProps) {
return (
<Space style={{ padding: '12px 20px', ...style }}>
<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>
);
}
function MonthBottomSlot({ style }: SlotProps) {
return (
<Space style={{ padding: '12px 20px', ...style }}>
<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>
);
}
export default function DatePickerDemo() {
const [activeTab, setActiveTab] = useState('1');
const [date, setDate] = useState<Date | Date[]>();
const handleTabChange = (tab: string) => {
setActiveTab(tab);
setDate(undefined);
};
const handleDateChange = (value: Date | Date[]) => {
setDate(value);
};
const disabledDate = activeTab === '1' ? uedDisabledDate : testDisabledDate;
return (
<div>
<DatePicker topSlot={<TopSlot activeKey={activeTab} onChange={handleTabChange} />} disabledDate={disabledDate} value={date} onChange={handleDateChange} dropdownClassName="components-datepicker-demo-slot" placeholder="请选择排期" />
<br />
<br />
<DatePicker bottomSlot={<BottomSlot />} placeholder="请选择发版时间" />
<br />
<br />
<DatePicker type="month" bottomSlot={<MonthBottomSlot />} placeholder="请选择年月" />
<br />
<br />
<DatePicker topSlot={<TopSlot activeKey={activeTab} onChange={handleTabChange} style={{ padding: '8px 12px 0' }} />} bottomSlot={<BottomSlot style={{ padding: '8px 12px' }} />} density="compact" placeholder="小尺寸" dropdownClassName="components-datepicker-demo-slot" />
<br />
<br />
<DatePicker type="dateTimeRange" bottomSlot={<BottomSlot />} style={{ width: 400 }} placeholder="请选择时间范围" />
<br />
<br />
</div>
);
}.components-datepicker-demo-slot {
.semi-tabs-content {
padding: 0;
}
.semi-tabs-bar-line.semi-tabs-bar-top {
border-bottom: none;
}
}
Disable Date Selection
Code
import { DatePicker } from '@fibrous/semi-ui-react';
const defaultValue = new Date(2019, 6, 23, 12);
export default function DatePickerDemo() {
return <DatePicker disabled type="dateTime" defaultValue={defaultValue} />;
}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
import { useCallback } from 'react';
import * as dateFns from 'date-fns';
import { range } from 'es-toolkit';
import { DatePicker, type DatePickerDisabledDateType, type DatePickerDisabledTimeType } from '@fibrous/semi-ui-react';
const nextValidMonth = new Date();
nextValidMonth.setMonth((nextValidMonth.getMonth() + 1) % 12);
export default function DatePickerDemo() {
const disabledTime = useCallback<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 = useCallback<DatePickerDisabledTimeType>((_date, panelType) => {
if (panelType === 'left') {
return { disabledHours: () => [17, 18] };
}
return { disabledHours: () => [12, 13, 14, 15, 16, 17, 18] };
}, []);
const disabledDate = useCallback<DatePickerDisabledDateType>((date) => {
const deadDate = new Date();
const month = deadDate.getMonth();
deadDate.setDate(28);
deadDate.setMonth((month + 1) % 12);
return !!date && date.getTime() < deadDate.getTime();
}, []);
return (
<div>
<div>
<h4>禁用时间:禁用今天下午5-6点</h4>
<DatePicker type="dateTime" hideDisabledOptions={false} disabledTime={disabledTime} />
</div>
<div>
<h4>禁用时间:两个面板禁用不同时间</h4>
<DatePicker type="dateTimeRange" hideDisabledOptions={false} disabledTime={disabledTime2} style={{ width: 400 }} />
</div>
<div>
<h4>禁用日期:禁用下个月28号之前的所有日期</h4>
<DatePicker type="dateTimeRange" disabledDate={disabledDate} defaultPickerValue={nextValidMonth} style={{ width: 400 }} />
</div>
</div>
);
}When type contains range, the date can be disabled dynamically according to the rangeStart. The options parameter is supported after 1.9.0
动态禁用日期:禁止选择之前的日期
Code
import * as dateFns from 'date-fns';
import { DatePicker } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
return (
<div>
<h4>动态禁用日期:禁止选择之前的日期</h4>
<DatePicker
type="dateRange"
disabledDate={(date, options) => {
if (!date || !options?.rangeStart) {
return false;
}
const startDate = dateFns.parseISO(options.rangeStart);
return dateFns.isBefore(date, startDate);
}}
style={{ width: 260 }}
/>
</div>
);
}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
import { useState } from 'react';
import * as dateFns from 'date-fns';
import { DatePicker, type DatePickerDisabledDateType } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
const [today] = useState(() => 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') {
const disabledStart = dateFns.subDays(baseDate, 2);
const disabledEnd = dateFns.addDays(baseDate, 2);
return disabledStart <= date && date <= disabledEnd;
} else if (rangeInputFocus === 'rangeEnd') {
const disabledStart = dateFns.subDays(baseDate, 3);
const disabledEnd = dateFns.addDays(baseDate, 3);
return disabledStart <= date && date <= disabledEnd;
} else {
return false;
}
};
return (
<div>
<h4>开始日期禁用今天前2日和后2日,结束日期禁用今天前3天和后3天</h4>
<DatePicker motion={false} type="dateRange" disabledDate={disabledDate} defaultPickerValue={today} />
</div>
);
}Custom Display Format
Pass parameter format to custom display format.
Code
import { DatePicker } from '@fibrous/semi-ui-react';
const defaultValue = new Date(2019, 6, 23, 12);
export default function DatePickerDemo() {
return <DatePicker format="yyyy年MM月dd日 HH:mm" type="dateTime" defaultValue={defaultValue} />;
}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 by passing the triggerRender method.
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.
Code
import { useState, useCallback, type MouseEvent } from 'react';
import * as dateFns from 'date-fns';
import { IconClose, IconChevronDown } from '@fibrous/semi-icons-react';
import { DatePicker, Button, ButtonGroup } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
const [date, setDate] = useState<Date | null>(() => new Date(2019, 6, 23, 12));
const formatToken = 'yyyy-MM-dd';
const onChange = useCallback((date: Date | Date[]) => {
setDate(date as Date);
}, []);
const onClear = useCallback((e?: MouseEvent) => {
e?.stopPropagation();
setDate(null);
}, []);
return (
<DatePicker
onChange={onChange}
value={date}
format={formatToken}
triggerRender={({ placeholder }) => (
// The clear button is a sibling of the trigger button: buttons cannot nest
<ButtonGroup theme="light">
<Button icon={<IconChevronDown />} iconPosition="right">
{(date && dateFns.format(date, formatToken)) || placeholder}
</Button>
{date && <Button icon={<IconClose />} aria-label="清除" onClick={onClear} />}
</ButtonGroup>
)}
/>
);
}Code
import { useState, useCallback, type MouseEvent } from 'react';
import * as dateFns from 'date-fns';
import { IconClose, IconChevronDown } from '@fibrous/semi-icons-react';
import { DatePicker, Button, ButtonGroup } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
const [date, setDate] = useState<Date | Date[]>();
const formatToken = 'yyyy-MM-dd HH:mm:ss';
const onChange = useCallback((date: Date | Date[]) => {
setDate(date);
console.log(date);
}, []);
const onClear = useCallback((e?: MouseEvent) => {
e?.stopPropagation();
setDate(undefined);
}, []);
const triggerContent = () => {
if (Array.isArray(date) && date.length) {
return `${dateFns.format(date[0], formatToken)} ~ ${dateFns.format(date[1], formatToken)}`;
} else {
return '请选择日期时间范围';
}
};
return (
<DatePicker
type="dateTimeRange"
onChange={onChange}
value={date}
triggerRender={() => (
// The clear button is a sibling of the trigger button: buttons cannot nest
<ButtonGroup theme="light">
<Button icon={<IconChevronDown />} iconPosition="right">
{triggerContent()}
</Button>
{date && <Button icon={<IconClose />} aria-label="清除" onClick={onClear} />}
</ButtonGroup>
)}
/>
);
}Custom Render Date Content
Version:>=1.4.0
renderDate: (dayNumber: number, fullDate: string) => ReactNode
dayNumber: such as13.fullDate: such as2020-08-13.
Code
import { DatePicker, Tooltip } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
const dateStyle = {
width: '100%',
height: '100%',
border: '1px solid var(--semi-color-primary)',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
};
const renderDate = (dayNumber?: number) => {
if (dayNumber === 1) {
return (
<Tooltip content="Always Day 1">
<div style={dateStyle}>{dayNumber}</div>
</Tooltip>
);
}
return dayNumber;
};
return <DatePicker renderDate={renderDate} />;
}Custom Render Date Box
Version:>=1.4.0
renderFullDate: (dayNumber: number, fullDate: string, dayStatus: object) => ReactNode
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
import clsx from 'clsx';
import { DatePicker, type DatePickerDayStatusType as DayStatusType } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
const renderFullDate = (dayNumber?: number, _fullDate?: string, { isInRange, isHover, isSelected, isSelectedStart, isSelectedEnd }: DayStatusType = {}) => {
const prefix = 'components-datepicker-demo';
const dateCls = clsx({
[`${prefix}-day-inrange`]: isInRange,
[`${prefix}-day-hover`]: isHover,
[`${prefix}-day-selected`]: isSelected,
[`${prefix}-day-selected-start`]: isSelectedStart,
[`${prefix}-day-selected-end`]: isSelectedEnd,
});
const dayStyle = {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '80%',
height: '80%',
borderRadius: 'var(--semi-border-radius-circle)',
};
return (
<div style={dayStyle} className={dateCls}>
{dayNumber}
</div>
);
};
return <DatePicker style={{ width: 260 }} type="dateRange" renderFullDate={renderFullDate} />;
}.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
| Property | Description | Type | Default |
|---|---|---|---|
| autoAdjustOverflow | Whether the popup flips its direction automatically when it is covered. | boolean | true |
| autoFocus | Whether the input is focused on mount. A range type focuses the start input when the panel is open. | boolean | - |
| autoSwitchDate | When the year or month is changed with the navigation buttons or dropdowns at the top of the panel, the date switches automatically. Only applies to the date type. | boolean | true |
| borderless | Borderless mode. | boolean | false |
| bottomSlot | Renders an extra area at the bottom. Takes a ReactNode. | React.ReactNode | - |
| className | Class name of the root element. | string | - |
| clearIcon | Custom icon of the clear button, effective when showClear is true. | React.ReactNode | - |
| defaultOpen | Whether the panel is open by default. | boolean | false |
| defaultPickerValue | Default panel date. Compared by content: when the content changes the panel moves back to it, so passing new Date() on every render counts as a change. | ValueType | - |
| defaultValue | Default value. | ValueType | - |
| density | Density of the picker panel, one of default and compact. | DensityType | "default" |
| disabled | Whether the picker is disabled. | boolean | - |
| disabledDate | Decides whether a date is disabled; returning true disables it. options carries the selected rangeStart and rangeEnd of a range and the focused input as rangeInputFocus. When type is year it is called with January 1 of each year, and returning true disables that year. | DisabledDateType | Type() => false |
| disabledTime | Time restriction configuration. Its return value is passed through to the TimePicker. | DisabledTimeType | Type() => ({}) |
| disabledTimePicker | Whether time selection is disabled. | MonthsGridFoundationProps['disabledTimePicker'] | - |
| dropdownClassName | Class name of the dropdown panel. | string | - |
| dropdownStyle | Inline style of the dropdown panel. | TypeRecord<string, any> | - |
| endDateOffset | When type is dateRange, sets the end date of a one-click range selection. | DateOffsetType | - |
| endYear | Last year of the year scroll panel, which must be greater than startYear. Defaults to 100 years after the current year. | number | - |
| format | Date string format shown in the input. When not set it depends on type; see Date and Time Format below. | string | - |
| hideDisabledOptions | Hides the disabled time options. | MonthsGridFoundationProps['hideDisabledOptions'] | false |
| inputReadOnly | Whether the input is readonly. | boolean | false |
| inputStyle | Inline style of the input. | TypeRecord<string, any> | - |
| insetInput | Whether the panel embeds input boxes. Takes a boolean, or an InsetInputProps object that sets the placeholders of the inset inputs. | DateInputFoundationProps['insetInput'] | false |
| insetLabel | Label shown in the input. The Form field injects it; used directly, DatePicker shows it in the input as well. | React.ReactNode | - |
| insetLabelId | id of the label element inside the input. The Form field injects it to name the input. | string | - |
| leftSlot | Renders an extra area on the left. Takes a ReactNode. | React.ReactNode | - |
| max | Maximum number of dates that can be selected when multiple is true. Unlimited when it is not set, or is null or undefined. | number | - |
| motion | Whether the panel animates when it opens. | boolean | true |
| multiple | Whether multiple dates can be selected. Only supports the date type. | boolean | false |
| needConfirm | Whether a confirm step is needed. Only effective for the dateTime and dateTimeRange types. | boolean | - |
| onBlur | Called when the panel closes; not recommended for range selection. e is the native mousedown event only when a click outside closes the panel; confirming, selecting a date, Esc and the other ways pass none. | Type(e?: MouseEvent) => void | - |
| onCancel | Called when the selection is cancelled, with the value of the last confirmed selection. Only effective for the dateTime and dateTimeRange types with needConfirm on. | OnCancelType | - |
| onChange | Called when the value changes. Both arguments are arrays for range and multiple selection. | Type(date: Date | Date[], dateString: string | string[]) => void | - |
| onClear | Called when the clear button is clicked, with the click event of the button. | TypeReact.MouseEventHandler<HTMLButtonElement> | - |
| onClickOutSide | Called when a mousedown lands outside the popup and the trigger while the popup is open. It receives the native mousedown event. | Type(e: MouseEvent) => void | - |
| onConfirm | Called when the selection is confirmed, with the current value. Only effective for the dateTime and dateTimeRange types with needConfirm on. | OnConfirmType | - |
| onFocus | Called when the picker gets focus; not recommended for range selection. e is the focus event of an input, or the click or key press on the trigger that focused the range start; rangeType is set only when a range input gets focus. | Type(e: React.FocusEvent | React.MouseEvent | React.KeyboardEvent, rangeType?: RangeInput | false) => void | - |
| onOpenChange | Called when the panel opens or closes, with whether it is now open. | Type(status: boolean) => void | - |
| onPanelChange | Called when the year or date shown in the panel changes. | OnPanelChangeType | - |
| onPresetClick | Called when a preset button is clicked, with the preset item and the click event. | Type(item: PresetType, e: React.MouseEvent<HTMLDivElement>) => void | - |
| open | Controlled open state of the panel, used together with onOpenChange. | boolean | - |
| placeholder | Placeholder of the input. A range type takes an array. When not set, the text comes from the locale package by type. | string | string[] | - |
| position | Popup position, with the same values as the position of Popover. When not set it is bottomLeft, or bottomRight in RTL; with insetInput and no position, the inline position is used. | Position | - |
| prefix | Prefix content of the input. | React.ReactNode | - |
| prefixCls | Class name prefix of the root element and the panel, usually left unchanged. | string | "semi-datepicker" |
| presetPosition | Position of the preset panel, one of left, right, top and bottom. | PresetPosition | "bottom" |
| presets | Preset shortcuts. start and end can be functions, which are evaluated when the preset is clicked. | PresetsType | - |
| preventScroll | Whether the browser scrolls the document to show a newly focused element. Applies to the focus method inside the component. | boolean | - |
| rangeSeparator | Separator between the two dates in a range input. String parsing uses it as well. | string | " ~ " |
| rangeSeparatorNode | Node rendered as the range separator. It only affects the display; string parsing still uses rangeSeparator. | React.ReactNode | - |
| ref | Handle object, not the root element. It carries the open, close, focus and blur methods, see Methods below. | TypeReact.Ref<DatePickerHandle> | - |
| renderDate | Customizes the content of a date. It receives the day number and the full date string, and returns a ReactNode. | Type(dayNumber?: number, fullDate?: string) => React.ReactNode | - |
| renderFullDate | Customizes the whole date cell. It receives the day number, the full date string and the day status, and returns a ReactNode. | Type(dayNumber?: number, fullDate?: string, dayStatus?: DayStatusType) => React.ReactNode | - |
| rightSlot | Renders an extra area on the right. Takes a ReactNode. | React.ReactNode | - |
| showClear | Whether the clear button is shown. Shown when not set. | boolean | - |
| size | Size of the input, one of small, default and large. | InputSize | "default" |
| spacing | Distance between the popup and the trigger. When not set it is 4, or 1 with insetInput and a position containing Over. | number | - |
| startDateOffset | When type is dateRange, sets the start date of a one-click range selection. | DateOffsetType | - |
| startYear | First year of the year scroll panel. Defaults to 100 years before the current year. | number | - |
| stopPropagation | Whether clicks on the popup stop propagating. | boolean | string | true |
| style | Inline style of the root element. | TypeRecord<string, any> | - |
| syncSwitchMonth | In range selection, whether the two panels switch months together. | boolean | false |
| timePickerOpts | Options for the time panel: use12Hours, hourStep, minuteStep, secondStep, defaultIsAM and scrollItemProps, see TimePicker API Reference; the panel sets the format, the value and onChange. | DatePickerTimePickerOpts | - |
| timeZone | Time zone in which the value and panel dates are read and shown. A string is an IANA time zone name such as Asia/Shanghai; a number is passed as is to utcToZonedTime of date-fns-tz. When not set, the time zone of ConfigProvider is used. | string | number | - |
| topSlot | Renders an extra area at the top. Takes a ReactNode. | React.ReactNode | - |
| triggerRender | Renders a custom trigger. It receives the trigger props (see the type definitions below) and returns a ReactNode. | Type(props: TriggerRenderProps) => React.ReactNode | - |
| type | Type, one of date, dateRange, dateTime, dateTimeRange, month, monthRange and year. | Type | "date" |
| validateStatus | Validation status, which only affects the display style. success looks the same as default. | ValidateStatus | - |
| value | Controlled value. | ValueType | null | - |
| weekStartsOn | Day of the week that starts each week: 0 is Sunday, 1 is Monday, and so on. | WeekStartNumber | 0 |
| yearAndMonthOpts | Other options passed to the year and month picker. list, onSelect, selectedIndex and type are set by the panel and are not accepted. | YearAndMonthOpts | - |
Methods
| Method | Description | Type |
|---|---|---|
| blur | Blurs the input. | Type() => void |
| close | Closes the panel. A controlled open takes precedence; when it is controlled, close does not change the visibility. | Type() => void |
| focus | Focuses the input. A range type focuses the start input by default, or the end input with 'rangeEnd'. With insetInput and the panel open, it focuses the input inside the panel. | Type(focusType?: RangeInput) => void |
| open | Opens the panel. A controlled open takes precedence; when it is controlled, open does not change the visibility. | Type() => void |
Other native attributes (such as id, title, data-*, aria-label and onClick) land on the root element, except tabIndex, which lands on the input. 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 takesaria-labelledby; the other four land on both inputs triggerRendercontent without a focusable element:aria-labelledby,aria-describedby,aria-errormessageandaria-invalidland on the wrapper with the rolebutton;aria-requiredis not forwardedtriggerRendercontent with its own focusable element: none of them is forwarded, so set them on the rendered content
Methods
The handle obtained through ref carries the open(), close(), focus(focusType?) and blur() methods, see the Methods table in the API Reference. focus focuses the input; a range type focuses the start input by default, or the end input with 'rangeEnd'. With insetInput and the panel open, it focuses the input inside the panel.
Code
import { useRef } from 'react';
import { DatePicker, Space, Button, type DatePickerHandle } from '@fibrous/semi-ui-react';
export default function DatePickerDemo() {
const ref = useRef<DatePickerHandle>(null);
const handleClickOutside = () => {
console.log('click outside');
};
return (
<Space vertical align="start">
<Space>
<Button onClick={() => ref.current?.open()}>open</Button>
<Button onClick={() => ref.current?.close()}>close</Button>
<Button onClick={() => ref.current?.focus()}>focus</Button>
<Button onClick={() => ref.current?.blur()}>blur</Button>
</Space>
<div>
<DatePicker type="dateTime" ref={ref} onClickOutSide={handleClickOutside} />
</div>
</Space>
);
}Interface Define
type BaseValueType = string | number | Date;
type ValueType = BaseValueType | BaseValueType[];
type DateType = Date | Date[];
type StringType = string | string[];
type TriggerRenderProps = {
value?: ValueType;
inputValue?: string | null;
placeholder?: string | string[];
autoFocus?: boolean;
size?: InputSize;
disabled?: boolean;
inputReadOnly?: boolean;
componentProps?: DatePickerProps;
[x: string]: any;
};
Accessibility
ARIA
- The input has the role
comboboxwitharia-haspopup="dialog", anaria-expandedthat follows the panel, andaria-controlspointing at the panel; both inputs of a range do - A single input is named
Choose datewhile no date is selected andChange dateonce one is (anaria-labelledbyyou pass wins) - When the content of a custom trigger (
triggerRenderin React, the#triggerslot in Vue) has no focusable element, the wrapper is the focus target with the rolebutton, 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 torow, and the date cell is set togridcell - The year and month scroll columns are
listboxlists named "year" and "month" aria-disabledis true for the corresponding option when date and time are disabled- With multiple or range selection,
aria-multiselectableof month is true, andaria-selectedof date grid is true when selected - Some decorative icons in the panel, their
aria-hiddenis true
Keyboard and Focus
Down Arrowin the input opens the panel; once the panel is open,Down Arrowmoves focus into it- The date grid is one Tab stop: the
arrow keys,Home,End,PageUpandPageDown(by year withShift) move the active date, andEnterorSpacepicks it - The date and time switches at the bottom of a dateTime panel are buttons that
EnterorSpaceactivates - With a range value, Tab reaches the clear button after the end input, and
EnterorSpaceclears the range Esccloses 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,SpaceorDown Arrowopens 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:
| type | format | display value |
|---|---|---|
| date | yyyy-MM-dd | 2023-12-09 |
| dateTime | yyyy-MM-dd HH:mm:ss | 2023-12-09 08:08:00 |
| month | yyyy-MM | 2023-12 |
| year | yyyy | 2023 |
| dateRange | yyyy-MM-dd | 2023-12-09 ~ 2023-12-10 |
| dateTimeRange | yyyy-MM-dd HH:mm:ss | 2023-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
| Sass variable | Value | Usage |
|---|---|---|
| $width-datepicker_day | 36px | 日期格子及星期标题尺寸 |
| $width-datepicker_day_main | 32px | 日期格子内容尺寸 |
| $width-datepicker_month | $width-datepicker_day * 7 | 日期视图单月面板宽度 |
| $width-datepicker_nav | 32px | 顶部导航栏高度 |
| $height-datepicker_switch | 54px | 日期时间切换高度 |
| $height-datepicker_timeType_yam | calc(100% - 54px) | 时间面板高度 |
| $height-datepicker_timeType_tpk | calc(100% - 54px) | 时间面板高度 |
| $height-datepicker_panel_yam_scrolllist | 266px | 年月选择列表滚动区域高度 |
| $width-datepicker_monthPanel_max | 284px | 年月选择器最大宽度 |
| $width-datepicker_monthRangePanel_max | 384px | 年月选择器最大宽度 |
| $height-datepicker_timepicker_header_min | 24px | 年月选择面板顶部导航栏最小高度 |
| $width-datepicker_navigation_button_min | 32px | 顶部导航栏按钮最小宽度 |
| $height-datepicker_yamShowing_min | 378px | 日期时间选择器菜单最小高度 |
| $width-datepicker_yamShowing_min | 284px | 选择器菜单最小宽度 |
| $height-datepicker_dateType_yamShowing_min | 325px | 日期选择器菜单最小高度 |
| $width-datepicker_panel_yam_scrolllist_li_min | 64px | 年月、时间滚动菜单项最小高度 |
| $width-datepicker_presetPanel_left_and_right | 200px | 左右方位快捷选择面板宽度 |
| $height-datepicker_presetPanel_top_and_bottom_max | 100px | 上下方位快捷选择面板最大高度 |
| $width-datepicker_presetPanel_scroll_bar | 15px | 快捷选择面板scrollbar宽度 |
| $width-datepicker-border | $border-thickness-control | 年月选择面板顶部导航栏底部分割线宽度 |
| $width-datepicker_yam_header-borderRadius | var(--semi-border-radius-medium) | 年月选择面板顶部导航栏圆角 |
| $width-datepicker_day_main-borderRadius | var(--semi-border-radius-small) | 日期格子圆角 |
| $width-datepicker_slot-border | 1px | 日期星期分割线宽度 |
| $width-datepicker_range_input-border | $border-thickness-control-focus | |
| $width-datepicker_day_main-border | 1px | |
| $height-datepicker_timeType_insetInput_yam | 100% | 时间面板高度 - 内嵌输入框 |
| $height-datepicker_timeType_insetInput_tpk | 100% | 时间面板高度 - 内嵌输入框 |
| $width-datepicker_insetInput_date_type_wrapper | 284px | 日期类型内嵌输入框宽度 |
| $width-datepicker_insetInput_date_range_type_wrapper | $width-datepicker_insetInput_date_type_wrapper * 2 | 范围选择内嵌输入框宽度 |
| $width-datepicker_insetInput_month_type_wrapper | 165px | 月份类型内嵌输入框宽度 |
| $width-datepicker_insetInput_month_range_type_wrapper | 331px | 年月范围类型内嵌输入框宽度 |
| $height-datepicker_insetInput_separator | 32px | |
| $height-datepicker_month_grid_yearType_insetInput | 317px | |
| $height-datepicker_month_grid_timeType_insetInput | 317px | |
| $width-datepicker_range_trigger-border | 0px | 触发器边框宽度 |
| $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-padding | 0 | 时间选择滚动菜单内边距 |
| $spacing-datepicker_footer-paddingTop | 10px | 确认选择 footer 顶部内边距 |
| $spacing-datepicker_footer-paddingBottom | 10px | 确认选择 footer 底部内边距 |
| $spacing-datepicker_footer-paddingRight | 8px | 确认选择 footer 右侧内边距 |
| $spacing-datepicker_footer_cancel_button-marginRight | 12px | 确认选择 footer 取消按钮右外边距 |
| $spacing-datepicker_footer_confirm_button-marginRight | 8px | 确认选择 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-paddingTop | 18px | 快捷预设面板标题区域上内边距 |
| $spacing-datepicker_quick_control_top_and_bottom_content-paddingX | $spacing-base-loose | 上下方位快捷操作面板, 左右内边距,默认20px |
| $spacing-datepicker_quick_control_content-paddingX | 12px | 快捷面板内容,左右内边距 |
| $spacing-datepicker_quick_control_content-marginTop | 14px | 快捷面板内容,上边距 |
| $spacing-datepicker_quick_control_item-margin | $spacing-tight | 快捷操作面板按钮间距 |
| $spacing-datepicker_range_input-paddingX | 8px | |
| $spacing-datepicker_range_input_inputWrapper_input-paddingY | 2px | |
| $spacing-datepicker_range_input_inputWrapper_input-paddingX | 4px | |
| $spacing-datepicker_range_input_prefix-paddingLeft | 12px | |
| $spacing-datepicker_range_input_prefix-paddingRight | 8px | |
| $spacing-datepicker_range_input_suffix-paddingLeft | 8px | |
| $spacing-datepicker_range_input_suffix-paddingRight | 12px | |
| $spacing-datepicker_range_input_clearbtn-paddingLeft | 8px | |
| $spacing-datepicker_range_input_clearbtn-paddingRight | 12px | |
| $spacing-datepicker_navigation_insetInput-paddingY | 8px | 年月切换 header 垂直内边距 - 内嵌输入框 |
| $spacing-datepicker_insetInput_wrapper-margin | 8px | |
| $spacing-datepicker_insetInput_wrapper-paddingY | 12px | |
| $spacing-datepicker_insetInput_wrapper-paddingX | 16px | |
| $spacing-datepicker_insetInput_wrapper-paddingBottom | 0 | |
| $spacing-datepicker_insetInput_separator-paddingY | 0 | |
| $spacing-datepicker_insetInput_separator-paddingX | 4px | |
| $color-datepicker_header-bg-default | var(--semi-color-bg-3) | 日期选择器 header 背景颜色 |
| $color-datepicker_list-bg-default | var(--semi-color-bg-3) | 日期选择器滚动列表背景颜色 |
| $color-datepicker_border-bg-default | var(--semi-color-border) | 日期选择器描边颜色 |
| $color-datepicker_footer-bg-default | var(--semi-color-fill-0) | 日期选择器确认选择 footer 背景颜色 |
| $color-datepicker_quick-bg-default | transparent | 日期选择器快捷操作背景颜色 |
| $color-datepicker_quick_button-text-default | var(--semi-color-primary) | 日期选择器快捷操作按钮文字颜色 |
| $color-datepicker_day-text-default | var(--semi-color-text-2) | 星期标题及日期时间切换按钮文字颜色 - 默认 |
| $color-datepicker_day-text-active | var(--semi-color-text-0) | 日期时间切换文字颜色 - 选中 |
| $color-datepicker_date-text-default | var(--semi-color-text-0) | 日期格子文字颜色 - 默认 |
| $color-datepicker_date-bg-default | var(--semi-color-fill-0) | 日期格子背景颜色 - 默认 |
| $color-datepicker_date-bg-hover | var(--semi-color-fill-0) | 日期格子背景颜色 - 悬浮 |
| $color-datepicker_date-bg-active | var(--semi-color-fill-1) | 日期格子背景颜色 - 按下 |
| $color-datepicker_date_selected-text-default | var(--semi-color-white) | 日期格子文字颜色 - 选中 |
| $color-datepicker_date_selected-bg-default | var(--semi-color-primary) | 日期格子背景颜色 - 选中 |
| $color-datepicker_date_disabled-text-default | var(--semi-color-disabled-text) | 禁用日期格子文字颜色 |
| $color-datepicker_date_disabled-bg-default | var(--semi-color-disabled-fill) | 禁用日期格子背景颜色 |
| $color-datepicker_date_today-text-default | var(--semi-color-primary) | 今日文字颜色 |
| $color-datepicker_date_today_disabled-text-default | var(--semi-color-primary-disabled) | 今日文字颜色 - 禁用 |
| $color-datepicker_date_inHover-bg-default | var(--semi-color-primary-light-default) | 范围选择日期格子颜色 |
| $color-datepicker_date_inRangeHover-bg-default | var(--semi-color-fill-0) | 范围选择时悬停路径内的日期背景色 |
| $color-datepicker_date_hoverDay-bg-default | var(--semi-color-fill-1) | 范围选择时日期格子背景色 - 悬停 |
| $color-datepicker_date_selectedRange-bg-hover | var(--semi-color-primary-light-hover) | 范围选择日期格子颜色 - 悬浮 |
| $color-datepicker_date_hoverday_range-bg-default | var(--semi-color-primary-light-active) | |
| $color-datepicker_date_hoverday_around_single_selected-bg-default | var(--semi-color-primary-light-active) | |
| $color-datepicker_nav_monthIcon-text-default | var(--semi-color-text-0) | 顶部导航栏年月文字颜色 - 默认 |
| $color-datepicker_navIcon-text-default | var(--semi-color-text-2) | 日期选择器 header 左右箭头颜色 |
| $color-datepicker_input_primary-text-default | var(--semi-color-primary) | |
| $color-datepicker_range_input-text-default | var(--semi-color-text-2) | |
| $color-datepicker_range_input-bg-default | var(--semi-color-fill-0) | |
| $color-datepicker_range_input-bg-hover | var(--semi-color-fill-1) | |
| $color-datepicker_range_input-border-default | transparent | |
| $color-datepicker_range_input-border-active | var(--semi-color-focus-border) | |
| $color-datepicker_range_input_warning-border-active | var(--semi-color-warning) | |
| $color-datepicker_range_input_warning-bg-active | var(--semi-color-warning-light-hover) | |
| $color-datepicker_range_input_warning-bg-default | var(--semi-color-warning-light-default) | |
| $color-datepicker_range_input_warning-bg-hover | var(--semi-color-warning-light-hover) | |
| $color-datepicker_range_input_warning-border-default | var(--semi-color-warning-light-default) | |
| $color-datepicker_range_input_error-border-default | var(--semi-color-danger-light-default) | |
| $color-datepicker_range_input_error-bg-hover | var(--semi-color-danger-light-hover) | |
| $color-datepicker_range_input_error-border-active | var(--semi-color-danger) | |
| $color-datepicker_range_input_error-bg-active | var(--semi-color-danger-light-hover) | |
| $color-datepicker_range_input_disabled-text-default | var(--semi-color-disabled-text) | |
| $color-datepicker_range_input_disabled-bg-default | var(--semi-color-disabled-fill) | |
| $color-datepicker_range_input_disabled-bg-hover | var(--semi-color-disabled-fill) | |
| $color-datepicker_range_input_clearbtn-icon-hover | var(--semi-color-primary-hover) | |
| $color-datepicker_range_input_inputWrapper-border-default | transparent | |
| $color-datepicker_range_input_inputWrapper-bg-default | transparent | |
| $color-datepicker_range_input_inputWrapper-bg-focus | var(--semi-color-fill-1) | |
| $color-datepicker_range_input_separator-text-active | var(--semi-color-text-0) | |
| $color-datepicker_day_main-border | var(--semi-color-primary-active) | |
| $color-datepicker_insetInput_separator | var(--semi-color-text-3) | |
| $color-datepicker_range_trigger-border | transparent | 范围日期选择模式触发器边框颜色 |
| $color-datepicker_range_trigger-border-hover | transparent | 范围日期选择模式触发器边框颜色 - 悬浮 |
| $color-datepicker_range_trigger-border-active | transparent | 范围日期选择模式触发器边框颜色 - 激活 |
| $color-datepicker_range_trigger-border-focus | transparent | 范围日期选择模式触发器边框颜色 - 聚焦 |
| $font-datepicker_range_input_prefix_suffix_clearbtn-fontWeight | 600 | |
| $font-datepicker_preset_header-fontWeight | 600 | |
| $font-datepicker_range_input_prefix_suffix_clearbtn-fontSize | 14px | |
| $font-datepicker_range_input_prefix_suffix_clearbtn-lineHeight | 20px | |
| $font-datepicker_range_input_large-fontSize | 16px | |
| $spacing-datepicker_month_compact-padding | 10px | |
| $width-datepicker_day_compact | 28px | |
| $width-datepicker_day_main_compact | 24px | |
| $width-datepicker_day_compact-borderRadius | 4px | |
| $width-datepicker_month_compact | $width-datepicker_day_compact * 7 + $spacing-datepicker_month_compact-padding * 2 | |
| $width-datepicker_nav_compact | 24px | |
| $width-datepicker_panel_compact | 216px | |
| $height-datepicker_switch_compact | 32px | |
| $height-datepicker_tpk_compact | 256px | |
| $height-datepicker_yam_panel_compact | 256px | |
| $height-datepicker_yam_li_compact | 32px | |
| $height-datepicker_yam_panel_header_compact | 48px | |
| $radius-datepicker_range_input_inputWrapper | var(--semi-border-radius-small) | |
| $height-datepicker_range_input-default | 32px | |
| $height-datepicker_range_input-small | 24px | |
| $height-datepicker_range_input-large | 40px | |
| $width-datepicker_insetInput_date_type_wrapper_compact | 216px | |
| $width-datepicker_insetInput_date_range_type_wrapper_compact | $width-datepicker_insetInput_date_type_wrapper_compact * 2 | |
| $width-datepicker_insetInput_month_type_wrapper_compact | 195px | |
| $height-datepicker_insetInput_tpk_compact | 100% | |
| $height-datepicker_timeType_insetInput_yam_compact | 100% | |
| $height-datepicker_insetInput_wrapper_compact | 28px | |
| $lineHeight-datepicker_compact | 20px | |
| $lineHeight-datepicker_weekday_item_compact | 28px | |
| $height-datepicker_insetInput_compact | 26px | |
| $fontSize-datepicker_insetInput_compact-fontSize | 12px | |
| $spacing-datepicker_switch_compact-padding | 6px | |
| $spacing-datepicker_day_compact-margin | ($width-datepicker_day_compact - $width-datepicker_day_main_compact) * 0.5 | |
| $spacing-datepicker_weeks_compact-padding | 10px | |
| $spacing-datepicker_weeks_compact-paddingTop | $spacing-tight - 2px | |
| $spacing-datepicker_weekday_compact-paddingLeft | 10px | |
| $spacing-datepicker_weekday_compact-paddingRight | 10px | |
| $spacing-datepicker_weekday_compact-paddingBottom | $spacing-tight | |
| $spacing-datepicker_nav_compact-padding | 12px | |
| $spacing-datepicker_yam_panel_header_compact-padding | 12px | |
| $spacing-datepicker_footer_compact-paddintTop | 10px | |
| $spacing-datepicker_footer_compact-paddintBottom | 10px | |
| $spacing-datepicker_footer_compact-paddintRight | 8px | |
| $spacing-datepicker_scrolllist_shade_pre_compact-marginTop | -17px | |
| $spacing-datepicker_scrolllist_shade_post_compact-marginTop | 17px | |
| $spacing-datepicker_insetInput_wrapper_compact-margin | 4px | |
| $spacing-datepicker_insetInput_wrapper_compact-paddingY | 8px | |
| $spacing-datepicker_insetInput_wrapper_compact-paddingX | 8px | |
| $spacing-datepicker_insetInput_wrapper_compact-paddingBottom | 0 | |
| $spacing-datepicker_insetInput_wrapper_rangeType_compact-paddingTop | 0 | |
| $spacing-datepicker_quick_control_header_compact-paddingTop | 16px | compact, 快捷面板标题,上内边距 |
| $spacing-datepicker_quick_control_content_compact-marginTop | 12px | compact, 快捷面板内容,上边距 |
| $spacing-datepicker_quick_control_left_and_right_content_compact-paddingX | 12px | compact,左右方位,快捷面板内容,左右内边距 |
| $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX | 10px | compact,上下方位,快捷面板内容,左右内边距 |
| $radius-datepicker_range_input | var(--semi-border-radius-small) | |
| $transition-datepicker_range_input | background-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 * 2 | date/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 * 2 | dateRange/dateTimeRange下, 上下方位快捷选择内容面板宽度,默认528px |
| $width-datepicker_presetPanel_top_and_bottom_content_month | 165px - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2 | month下,上下方位快捷选择内容面板宽度, 默认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 * 2 | date/dateRange,面板渲染最大高度,默认325px |
| $height-datepicker_date_time_panel | $height-datepicker_date_panel + $height-datepicker_switch - 1px | dateTime/dateTImeRange 面板渲染最大高度. 默认378px |
| $height-datepicker_presetPanel_left_and_right_except_content | 20px + $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 * 2 | date/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 * 2 | dateRange/dateTimeRange下, 上下方位快捷选择内容面板宽度,默认412px |
| $width-datepicker_presetPanel_top_and_bottom_content_month_compact | 165px - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2 | month下,上下方位快捷选择内容面板宽度, 默认174px |
| $height-datepicker_date_panel_compact | $height-datepicker_month_max_compact + $width-datepicker_nav_compact + $spacing-datepicker_nav_compact-padding | compact,date/dateRange,面板渲染最大高度,默认256px |
| $height-datepicker_date_time_panel_compact | $height-datepicker_date_panel_compact + $height-datepicker_switch_compact | compact,dateTime/dateTImeRange,面板渲染最大高度,默认288px |
| $height-datepicker_presetPanel_left_and_right_except_content_compact | 20px + $spacing-datepicker_quick_control_header_compact-paddingTop + $spacing-datepicker_quick_control_content_compact-marginTop | compact,除去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_input | 32px + $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_input | inset_input下,非month面板渲染最大高度,默认361px |
| $height-datepicker_inset_input_compact | 28px + $spacing-datepicker_insetInput_wrapper_compact-paddingY | compact,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_compact | inset_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
dateTimetype, the full requested date and time have been entered. FordateRangetype, 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.