DesktopDateTimePickerAPI
React DesktopDateTimePicker 元件的 API 參考文件。瞭解此匯出模組的 props、CSS 和其他 API。
範例展示
匯入
import { DesktopDateTimePicker } from '@mui/x-date-pickers/DesktopDateTimePicker';
// or
import { DesktopDateTimePicker } from '@mui/x-date-pickers';
// or
import { DesktopDateTimePicker } from '@mui/x-date-pickers-pro';
閱讀關於最小化套件大小的指南,以瞭解差異。
名稱 | 類型 | 預設值 | 描述 |
---|---|---|---|
ampm | bool | utils.is12HourCycleInCurrentLocale() | 小時選取時鐘的 12 小時制/24 小時制檢視。 |
ampmInClock | bool | 桌上型電腦為 true,行動裝置為 false | 在時鐘下方(而非工具列中)顯示 ampm 控制項。 |
autoFocus | bool | - | 若為 |
closeOnSelect | bool | 桌上型電腦為 true ,行動裝置為 false (根據所選的 wrapper 和 desktopModeMediaQuery prop)。 | 若為 |
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 | 若為 |
disableIgnoringDatePartForTimeValidation | bool | false | 驗證最小/最大時間時,不要忽略日期部分。 |
disableOpenPicker | bool | false | 若為 |
disablePast | bool | false | 若為 |
displayWeekNumber | bool | - | 若為 |
fixedWeekNumber | number | - | 日期檢視將顯示在當月結束後所需週數,以符合此值。設為 6 以在格里曆中固定週數 |
format | string | - | 在輸入中轉譯時的日期格式。預設為根據使用的 |
formatDensity | 'dense' | 'spacious' | "dense" | 在輸入中轉譯時的格式密度。將 |
inputRef | ref | - | 將 ref 傳遞至 |
label | node | - | 標籤內容。 |
loading | bool | false | 若為 |
localeText | object | - | 元件文字的 Locale。允許覆寫來自 |
maxDate | object | 2099-12-31 | 最大可選日期。 |
maxDateTime | object | - | 最大可選時間點,與日期繫結,若要設定每天的最大時間,請使用 |
maxTime | object | - | 最大可選時間。除非 |
minDate | object | 1900-01-01 | 最小可選日期。 |
minDateTime | object | - | 最小可選時間點,與日期繫結,若要設定每天的最小時間,請使用 |
minTime | object | - | 最小可選時間。除非 |
minutesStep | number | 1 | 分鐘的步進值。 |
monthsPerRow | 3 | 4 | 3 | 每列轉譯的月份數。 |
name | string | - | Field 中 |
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
|
onOpen | func | - | 當快顯視窗要求開啟時觸發的回呼。在受控制模式下使用(請參閱 |
onSelectedSectionsChange | func | - | 當選取的區段變更時觸發的回呼。 簽章: function(newValue: FieldSelectedSections) => void
|
onViewChange | func | - | 在檢視變更時觸發的回呼。 簽章: function(view: TView) => void
|
onYearChange | func | - | 在年份變更時觸發的回呼。 簽章: function(year: TDate) => void
|
open | bool | false | 控制快顯視窗或對話方塊的開啟狀態。 |
openTo | 'day' | 'hours' | 'meridiem' | 'minutes' | 'month' | 'seconds' | '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 傳回值: 載入時要轉譯的節點。 |
selectedSections | 'all' | 'day' | 'empty' | 'hours' | 'meridiem' | 'minutes' | 'month' | 'seconds' | 'weekDay' | 'year' | number | - | 目前選取的區段。此 prop 接受四種格式:1. 若提供數字,則會選取此索引處的區段。2. 若提供 |
shouldDisableDate | func | - | 停用特定日期。 簽章: function(day: TDate) => boolean
傳回值: 若為 |
shouldDisableMonth | func | - | 停用特定月份。 簽章: function(month: TDate) => boolean
傳回值: 若為 |
shouldDisableTime | func | - | 停用特定時間。 簽章: function(value: TDate, view: TimeView) => boolean
傳回值: 若為 |
shouldDisableYear | func | - | 停用特定年份。 簽章: function(year: TDate) => boolean
傳回值: 若為 |
showDaysOutsideCurrentMonth | bool | false | 若為 |
skipDisabled | bool | false | 若為 |
slotProps | object | {} | 用於每個元件 slot 的 props。 |
slots | object | {} | 可覆寫的元件 slot。 請參閱下方的Slots API 以取得更多詳細資訊。 |
sx | Array<func | object | bool> | func | object | - | 允許定義系統覆寫以及其他 CSS 樣式的系統 prop。 請參閱 `sx` 頁面 以取得更多詳細資訊。 |
thresholdToRenderTimeInASingleColumn | number | 24 | 低於或等於此時間選項數量時,將使用單欄時間轉譯器。 |
timeSteps | { hours?: number, minutes?: number, seconds?: number } | { hours: 1, minutes: 5, seconds: 5 } | 兩個時間單位選項之間的時間步進值。例如,若 |
timezone | string | 已定義 value 或 defaultValue prop 的時區,否則為 'default'。 | 選擇要用於值的時區。範例:"default"、"system"、"UTC"、"America/New_York"。若您將來自其他時區的值傳遞至某些 props,它們會在被使用前轉換為此時區。 請參閱 時區文件 以取得更多詳細資訊。 |
value | object | - | 選取的值。當元件受控制時使用。 |
view | 'day' | 'hours' | 'meridiem' | 'minutes' | 'month' | 'seconds' | 'year' | - | 可見檢視。當元件檢視受控制時使用。必須是 |
viewRenderers | { day?: func, hours?: func, meridiem?: func, minutes?: func, month?: func, seconds?: func, year?: func } | - | 為每個區段定義自訂檢視轉譯器。若為 |
views | Array<'day' | 'hours' | 'minutes' | 'month' | 'seconds' | 'year'> | - | 可用的檢視。 |
yearsOrder | 'asc' | 'desc' | 'asc' | 年份預設以遞增(依時間順序)順序顯示。若為 |
yearsPerRow | 3 | 4 | 4 | 每列轉譯的年份數。 |
ref
會轉發至根元素。Slot 名稱 | 類別名稱 | 預設元件 | 描述 |
---|---|---|---|
actionBar | PickersActionBar | 動作列的自訂元件,它位於選擇器檢視下方。 | |
calendarHeader | PickersCalendarHeader | 日曆標題的自訂元件。查看 PickersCalendarHeader 元件。 | |
clearButton | IconButton | 清除值的按鈕。 | |
clearIcon | ClearIcon | 在清除按鈕內顯示的圖示。 | |
day | PickersDay | 日期的自訂元件。查看 PickersDay 元件。 | |
desktopPaper | PickersPopperPaper | 在桌上型電腦選擇器的 Popper 內轉譯的 paper 自訂元件。 | |
desktopTransition | 當 | 桌上型電腦 popper 的自訂元件 Transition。 | |
desktopTrapFocus | 來自 '@mui/material' 的 TrapFocus。 | 用於在桌上型電腦上將焦點鎖定在檢視內的自訂元件。 | |
digitalClockItem | 來自 '@mui/material' 的 MenuItem | 負責轉譯單一數位時鐘項目的元件。 | |
digitalClockSectionItem | 來自 '@mui/material' 的 MenuItem | 負責轉譯單一多區段數位時鐘區段項目的元件。 | |
field | 用於使用鍵盤輸入日期的元件。 | ||
inputAdornment | InputAdornment | 在開始或結束輸入裝飾中顯示的元件,用於在桌上型電腦上開啟選擇器。 | |
layout | 用於包裝版面配置的自訂元件。它包裝工具列、檢視、動作列和快捷鍵。 | ||
leftArrowIcon | ArrowLeft | 在左檢視切換按鈕中顯示的圖示。 | |
monthButton | MonthCalendarButton | 顯示以在 month 檢視中轉譯單一月份的按鈕。 | |
nextIconButton | IconButton | 允許切換到正確檢視的按鈕。 | |
openPickerButton | IconButton | 在桌上型電腦上開啟選擇器的按鈕。 | |
openPickerIcon | 在桌上型電腦上的開啟選擇器按鈕中顯示的圖示。 | ||
popper | 來自 '@mui/material' 的 Popper。 | 在其中轉譯桌上型電腦上檢視的 popper 自訂元件。 | |
previousIconButton | IconButton | 允許切換到錯誤檢視的按鈕。 | |
rightArrowIcon | ArrowRight | 在正確檢視切換按鈕中顯示的圖示。 | |
shortcuts | PickersShortcuts | 快捷鍵的自訂元件。 | |
switchViewButton | IconButton | 顯示以在不同日曆檢視之間切換的按鈕。 | |
switchViewIcon | ArrowDropDown | 在 SwitchViewButton 中顯示的圖示。當開啟的檢視為 year 時旋轉 180°。 | |
tabs | DateTimePickerTabs | 啟用在日期和時間選擇器之間切換的 Tabs。 | |
textField | 來自 '@mui/material' 的 TextField,若 | 具有輸入的表單控制項,用於在預設欄位內轉譯值。 | |
toolbar | DateTimePickerToolbar | 在檢視上方轉譯的工具列自訂元件。 | |
yearButton | YearCalendarButton | 顯示以在 year 檢視中轉譯單一年份的按鈕。 |
原始碼
若您在此頁面中找不到資訊,請考慮查看元件的實作以取得更多詳細資訊。