StaticDatePickerAPI
React StaticDatePicker 组件的 API 参考文档。 了解此导出模块的 props、CSS 和其他 API。
演示
导入
import { StaticDatePicker } from '@mui/x-date-pickers/StaticDatePicker';
// or
import { StaticDatePicker } from '@mui/x-date-pickers';
// or
import { StaticDatePicker } from '@mui/x-date-pickers-pro';
通过阅读关于最小化 bundle size 的指南,了解它们之间的区别。
名称 | 类型 | 默认 | 描述 |
---|---|---|---|
autoFocus | bool | - | 如果 |
dayOfWeekFormatter | func | (date: TDate) => adapter.format(date, 'weekdayShort').charAt(0).toUpperCase() | 格式化日历标题中显示的星期几。 签名: function(date: TDate) => string
返回: 要显示的名称。 |
defaultValue | object | - | 默认值。 当组件不受控制时使用。 |
disabled | bool | false | 如果 |
disableFuture | bool | false | 如果 |
disableHighlightToday | bool | false | 如果 |
disablePast | bool | false | 如果 |
displayStaticWrapperAs | 'desktop' | 'mobile' | "mobile" | 强制静态包装器内部组件以移动或桌面模式渲染。 |
displayWeekNumber | bool | - | 如果 |
fixedWeekNumber | number | - | 日期视图将显示当前月份结束后所需的周数,以匹配此值。 设置为 6 以在公历中获得固定周数 |
loading | bool | false | 如果 |
localeText | object | - | 组件文本的区域设置。 允许覆盖来自 |
maxDate | object | 2099-12-31 | 最大可选择日期。 |
minDate | object | 1900-01-01 | 最小可选择日期。 |
monthsPerRow | 3 | 4 | 3 | 每行渲染的月份数。 |
onAccept | func | - | 当值被接受时触发的回调。 签名: function(value: TValue, context: FieldChangeHandlerContext
|
onChange | func | - | 当值更改时触发的回调。 签名: function(value: TValue, context: FieldChangeHandlerContext
|
onClose | func | - | 当组件请求关闭时触发的回调。 可以在选择(默认情况下在 |
onError | func | - | 当与当前值关联的错误更改时触发的回调。 当检测到验证错误时, 签名: function(error: TError, value: TValue) => void
|
onMonthChange | func | - | 在月份更改时触发的回调。 签名: function(month: TDate) => void
|
onViewChange | func | - | 在视图更改时触发的回调。 签名: function(view: TView) => void
|
onYearChange | func | - | 在年份更改时触发的回调。 签名: function(year: TDate) => void
|
openTo | 'day' | 'month' | 'year' | - | 默认可见视图。 当组件视图不受控制时使用。 必须是 |
orientation | 'landscape' | 'portrait' | - | 强制以特定方向渲染。 |
reduceAnimations | bool | `@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` 匹配 Android <10 或 iOS <13 | 如果 |
referenceDate | object | 使用验证 props 的最接近的有效日期时间,除了像 shouldDisable<...> 这样的回调。 | 当 |
renderLoading | func | () => <span>...</span> | 当传递 签名: function() => React.ReactNode 返回: 加载时要渲染的节点。 |
shouldDisableDate | func | - | 禁用特定日期。 签名: function(day: TDate) => boolean
返回: 如果 |
shouldDisableMonth | func | - | 禁用特定月份。 签名: function(month: TDate) => boolean
返回: 如果 |
shouldDisableYear | func | - | 禁用特定年份。 签名: function(year: TDate) => boolean
返回: 如果 |
showDaysOutsideCurrentMonth | bool | false | 如果 |
slotProps | object | {} | 用于每个组件插槽的 props。 |
slots | object | {} | 可覆盖的组件插槽。 有关更多详细信息,请参见下面的 Slots API。 |
sx | Array<func | object | bool> | func | object | - | 允许定义系统覆盖以及其他 CSS 样式的系统 prop。 有关更多详细信息,请参见 `sx` 页面。 |
timezone | string | 定义了 value 或 defaultValue prop 的时区,否则为 'default'。 | 选择用于值的时区。 示例:“default”、“system”、“UTC”、“America/New_York”。 如果将来自其他时区的值传递给某些 props,则它们将在使用前转换为此时区。 有关更多详细信息,请参见 时区文档。 |
value | object | - | 选定的值。 当组件受控时使用。 |
view | 'day' | 'month' | 'year' | - | 可见视图。 当组件视图受控时使用。 必须是 |
viewRenderers | { day?: func, month?: func, year?: func } | - | 为每个部分定义自定义视图渲染器。 如果为 |
views | Array<'day' | 'month' | 'year'> | - | 可用视图。 |
yearsOrder | 'asc' | 'desc' | 'asc' | 默认情况下,年份按升序(按时间顺序)显示。 如果为 |
yearsPerRow | 3 | 4 | `4` 当 displayStaticWrapperAs === 'desktop' 时,否则为 3 。 | 每行渲染的年份数。 |
ref
被转发到根元素。插槽名称 | 类名 | 默认组件 | 描述 |
---|---|---|---|
actionBar | PickersActionBar | 操作栏的自定义组件,它位于选择器视图下方。 | |
calendarHeader | PickersCalendarHeader | 日历标题的自定义组件。 检查 PickersCalendarHeader 组件。 | |
day | PickersDay | 日期的自定义组件。 检查 PickersDay 组件。 | |
layout | 用于包装布局的自定义组件。 它包装工具栏、视图、操作栏和快捷方式。 | ||
leftArrowIcon | ArrowLeft | 在左视图切换按钮中显示的图标。 | |
monthButton | MonthCalendarButton | 用于在 month 视图中渲染单个月份的按钮。 | |
nextIconButton | IconButton | 允许切换到右视图的按钮。 | |
previousIconButton | IconButton | 允许切换到左视图的按钮。 | |
rightArrowIcon | ArrowRight | 在右视图切换按钮中显示的图标。 | |
shortcuts | PickersShortcuts | 快捷方式的自定义组件。 | |
switchViewButton | IconButton | 用于在不同日历视图之间切换的按钮。 | |
switchViewIcon | ArrowDropDown | 在 SwitchViewButton 中显示的图标。 当打开的视图为 year 时,旋转 180°。 | |
toolbar | DatePickerToolbar | 在视图上方渲染的工具栏的自定义组件。 | |
yearButton | YearCalendarButton | 用于在 year 视图中渲染单个年份的按钮。 |
源代码
如果您在此页面中找不到信息,请考虑查看组件的实现以获取更多详细信息。