From 826d3d9cb1c9801da18d4ce57821fdd47d557b74 Mon Sep 17 00:00:00 2001 From: flavien Date: Wed, 20 Nov 2024 14:55:54 +0100 Subject: [PATCH] Use the new ownerState object in all the field components --- .../MultiInputDateRangeField.tsx | 17 +++++---- .../MultiInputDateRangeField.types.ts | 36 ++++++++----------- .../MultiInputDateTimeRangeField.tsx | 17 +++++---- .../MultiInputDateTimeRangeField.types.ts | 34 +++++++----------- .../MultiInputTimeRangeField.tsx | 17 +++++---- .../MultiInputTimeRangeField.types.ts | 34 +++++++----------- .../SingleInputDateRangeField.tsx | 7 ++-- .../SingleInputDateRangeField.types.ts | 21 ++++++----- .../SingleInputDateTimeRangeField.tsx | 7 ++-- .../SingleInputDateTimeRangeField.types.ts | 21 ++++++----- .../SingleInputTimeRangeField.tsx | 7 ++-- .../SingleInputTimeRangeField.types.ts | 21 ++++++----- .../hooks/useEnrichedRangePickerFieldProps.ts | 14 +++++--- .../src/internals/models/fields.ts | 10 ++---- .../src/DateField/DateField.tsx | 3 +- .../src/DateField/DateField.types.ts | 20 +++++------ .../src/DateTimeField/DateTimeField.tsx | 3 +- .../src/DateTimeField/DateTimeField.types.ts | 23 ++++++------ .../src/TimeField/TimeField.tsx | 3 +- .../src/TimeField/TimeField.types.ts | 23 ++++++------ .../useDesktopPicker.types.ts | 17 +++++---- .../src/internals/hooks/useFieldOwnerState.ts | 19 ++++++++++ .../useMobilePicker/useMobilePicker.types.ts | 11 ++++-- .../x-date-pickers/src/internals/index.ts | 1 + packages/x-date-pickers/src/models/fields.ts | 12 +++++++ scripts/x-date-pickers-pro.exports.json | 1 + scripts/x-date-pickers.exports.json | 1 + 27 files changed, 216 insertions(+), 184 deletions(-) create mode 100644 packages/x-date-pickers/src/internals/hooks/useFieldOwnerState.ts diff --git a/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.tsx b/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.tsx index c3c9fb73c19d..8d3374254a0e 100644 --- a/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.tsx +++ b/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.tsx @@ -12,7 +12,10 @@ import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses, } from '@mui/utils'; -import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals'; +import { + convertFieldResponseIntoMuiTextFieldProps, + useFieldOwnerState, +} from '@mui/x-date-pickers/internals'; import { useSplitFieldProps } from '@mui/x-date-pickers/hooks'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import { @@ -30,8 +33,7 @@ export const multiInputDateRangeFieldClasses: MultiInputRangeFieldClasses = gene export const getMultiInputDateRangeFieldUtilityClass = (slot: string) => generateUtilityClass('MuiMultiInputDateRangeField', slot); -const useUtilityClasses = (ownerState: MultiInputDateRangeFieldProps) => { - const { classes } = ownerState; +const useUtilityClasses = (classes: Partial | undefined) => { const slots = { root: ['root'], separator: ['separator'], @@ -95,11 +97,12 @@ const MultiInputDateRangeField = React.forwardRef(function MultiInputDateRangeFi unstableStartFieldRef, unstableEndFieldRef, className, + classes: classesProp, ...otherForwardedProps } = forwardedProps; - const ownerState = themeProps; - const classes = useUtilityClasses(ownerState); + const ownerState = useFieldOwnerState(internalProps); + const classes = useUtilityClasses(classesProp); const Root = slots?.root ?? MultiInputDateRangeFieldRoot; const rootProps = useSlotProps({ @@ -118,7 +121,7 @@ const MultiInputDateRangeField = React.forwardRef(function MultiInputDateRangeFi (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField); const startTextFieldProps = useSlotProps< typeof TextField, - MultiInputDateRangeFieldSlotProps['textField'], + MultiInputDateRangeFieldSlotProps['textField'], {}, MultiInputDateRangeFieldProps & { position: RangePosition; @@ -130,7 +133,7 @@ const MultiInputDateRangeField = React.forwardRef(function MultiInputDateRangeFi }); const endTextFieldProps = useSlotProps< typeof TextField, - MultiInputDateRangeFieldSlotProps['textField'], + MultiInputDateRangeFieldSlotProps['textField'], {}, MultiInputDateRangeFieldProps & { position: RangePosition; diff --git a/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.types.ts b/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.types.ts index 8b31315cee9f..6565d64012de 100644 --- a/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.types.ts +++ b/packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.types.ts @@ -1,8 +1,10 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import Typography from '@mui/material/Typography'; -import Stack, { StackProps } from '@mui/material/Stack'; -import TextField from '@mui/material/TextField'; +import type { TypographyProps } from '@mui/material/Typography'; +import type { StackProps } from '@mui/material/Stack'; +import type { TextFieldProps } from '@mui/material/TextField'; +import { FieldOwnerState } from '@mui/x-date-pickers/models'; +import { SlotComponentPropsFromProps } from '@mui/x-internals/types'; +import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField'; import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types'; import { MultiInputFieldRefs, @@ -53,7 +55,7 @@ export interface MultiInputDateRangeFieldProps< * The props used for each component slot. * @default {} */ - slotProps?: MultiInputDateRangeFieldSlotProps; + slotProps?: MultiInputDateRangeFieldSlotProps; } export interface MultiInputDateRangeFieldSlots { @@ -65,7 +67,7 @@ export interface MultiInputDateRangeFieldSlots { /** * Form control with an input to render a date. * It is rendered twice: once for the start date and once for the end date. - * @default TextField from '@mui/material' or PickersTextField if `enableAccessibleFieldDOMStructure` is `true`. + * @default , or from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`. */ textField?: React.ElementType; /** @@ -75,24 +77,14 @@ export interface MultiInputDateRangeFieldSlots { separator?: React.ElementType; } -export interface MultiInputDateRangeFieldSlotProps< - TEnableAccessibleFieldDOMStructure extends boolean, -> { - root?: SlotComponentProps< - typeof Stack, - {}, - MultiInputDateRangeFieldProps - >; - textField?: SlotComponentProps< - typeof TextField, +export interface MultiInputDateRangeFieldSlotProps { + root?: SlotComponentPropsFromProps; + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - MultiInputDateRangeFieldProps & { + FieldOwnerState & { position: RangePosition; } >; - separator?: SlotComponentProps< - typeof Typography, - {}, - MultiInputDateRangeFieldProps - >; + separator?: SlotComponentPropsFromProps; } diff --git a/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.tsx b/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.tsx index 3531d3a14dd9..9646b7c5304c 100644 --- a/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.tsx +++ b/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.tsx @@ -12,7 +12,10 @@ import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses, } from '@mui/utils'; -import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals'; +import { + convertFieldResponseIntoMuiTextFieldProps, + useFieldOwnerState, +} from '@mui/x-date-pickers/internals'; import { useSplitFieldProps } from '@mui/x-date-pickers/hooks'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import { @@ -28,8 +31,7 @@ export const multiInputDateTimeRangeFieldClasses: MultiInputRangeFieldClasses = export const getMultiInputDateTimeRangeFieldUtilityClass = (slot: string) => generateUtilityClass('MuiMultiInputDateTimeRangeField', slot); -const useUtilityClasses = (ownerState: MultiInputDateTimeRangeFieldProps) => { - const { classes } = ownerState; +const useUtilityClasses = (classes: Partial | undefined) => { const slots = { root: ['root'], separator: ['separator'], @@ -93,11 +95,12 @@ const MultiInputDateTimeRangeField = React.forwardRef(function MultiInputDateTim unstableStartFieldRef, unstableEndFieldRef, className, + classes: classesProp, ...otherForwardedProps } = forwardedProps; - const ownerState = themeProps; - const classes = useUtilityClasses(ownerState); + const ownerState = useFieldOwnerState(themeProps); + const classes = useUtilityClasses(classesProp); const Root = slots?.root ?? MultiInputDateTimeRangeFieldRoot; const rootProps = useSlotProps({ @@ -116,7 +119,7 @@ const MultiInputDateTimeRangeField = React.forwardRef(function MultiInputDateTim (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField); const startTextFieldProps = useSlotProps< typeof TextField, - MultiInputDateTimeRangeFieldSlotProps['textField'], + MultiInputDateTimeRangeFieldSlotProps['textField'], {}, MultiInputDateTimeRangeFieldProps & { position: RangePosition; @@ -128,7 +131,7 @@ const MultiInputDateTimeRangeField = React.forwardRef(function MultiInputDateTim }); const endTextFieldProps = useSlotProps< typeof TextField, - MultiInputDateTimeRangeFieldSlotProps['textField'], + MultiInputDateTimeRangeFieldSlotProps['textField'], {}, MultiInputDateTimeRangeFieldProps & { position: RangePosition; diff --git a/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.ts b/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.ts index e66073ee71f5..51675345af78 100644 --- a/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.ts +++ b/packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.ts @@ -1,8 +1,10 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import Typography from '@mui/material/Typography'; -import Stack, { StackProps } from '@mui/material/Stack'; -import TextField from '@mui/material/TextField'; +import type { TypographyProps } from '@mui/material/Typography'; +import type { StackProps } from '@mui/material/Stack'; +import type { TextFieldProps } from '@mui/material/TextField'; +import { FieldOwnerState } from '@mui/x-date-pickers/models'; +import { SlotComponentPropsFromProps } from '@mui/x-internals/types'; +import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField'; import { UseDateTimeRangeFieldProps } from '../internals/models/dateTimeRange'; import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types'; import { MultiInputFieldRefs, MultiInputRangeFieldClasses, RangePosition } from '../models'; @@ -52,7 +54,7 @@ export interface MultiInputDateTimeRangeFieldProps< * The props used for each component slot. * @default {} */ - slotProps?: MultiInputDateTimeRangeFieldSlotProps; + slotProps?: MultiInputDateTimeRangeFieldSlotProps; } export interface MultiInputDateTimeRangeFieldSlots { @@ -74,24 +76,14 @@ export interface MultiInputDateTimeRangeFieldSlots { separator?: React.ElementType; } -export interface MultiInputDateTimeRangeFieldSlotProps< - TEnableAccessibleFieldDOMStructure extends boolean, -> { - root?: SlotComponentProps< - typeof Stack, - {}, - MultiInputDateTimeRangeFieldProps - >; - textField?: SlotComponentProps< - typeof TextField, +export interface MultiInputDateTimeRangeFieldSlotProps { + root?: SlotComponentPropsFromProps; + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - MultiInputDateTimeRangeFieldProps & { + FieldOwnerState & { position: RangePosition; } >; - separator?: SlotComponentProps< - typeof Typography, - {}, - MultiInputDateTimeRangeFieldProps - >; + separator?: SlotComponentPropsFromProps; } diff --git a/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.tsx b/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.tsx index c533888fd193..7a1ce39ae4a7 100644 --- a/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.tsx +++ b/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.tsx @@ -12,7 +12,10 @@ import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses, } from '@mui/utils'; -import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals'; +import { + convertFieldResponseIntoMuiTextFieldProps, + useFieldOwnerState, +} from '@mui/x-date-pickers/internals'; import { useSplitFieldProps } from '@mui/x-date-pickers/hooks'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import { @@ -30,8 +33,7 @@ export const multiInputTimeRangeFieldClasses: MultiInputRangeFieldClasses = gene export const getMultiInputTimeRangeFieldUtilityClass = (slot: string) => generateUtilityClass('MuiMultiInputTimeRangeField', slot); -const useUtilityClasses = (ownerState: MultiInputTimeRangeFieldProps) => { - const { classes } = ownerState; +const useUtilityClasses = (classes: Partial | undefined) => { const slots = { root: ['root'], separator: ['separator'], @@ -95,11 +97,12 @@ const MultiInputTimeRangeField = React.forwardRef(function MultiInputTimeRangeFi unstableStartFieldRef, unstableEndFieldRef, className, + classes: classesProp, ...otherForwardedProps } = forwardedProps; - const ownerState = themeProps; - const classes = useUtilityClasses(ownerState); + const ownerState = useFieldOwnerState(themeProps); + const classes = useUtilityClasses(classesProp); const Root = slots?.root ?? MultiInputTimeRangeFieldRoot; const rootProps = useSlotProps({ @@ -118,7 +121,7 @@ const MultiInputTimeRangeField = React.forwardRef(function MultiInputTimeRangeFi (inProps.enableAccessibleFieldDOMStructure === false ? MuiTextField : PickersTextField); const startTextFieldProps = useSlotProps< typeof TextField, - MultiInputTimeRangeFieldSlotProps['textField'], + MultiInputTimeRangeFieldSlotProps['textField'], {}, MultiInputTimeRangeFieldProps & { position: RangePosition; @@ -131,7 +134,7 @@ const MultiInputTimeRangeField = React.forwardRef(function MultiInputTimeRangeFi const endTextFieldProps = useSlotProps< typeof TextField, - MultiInputTimeRangeFieldSlotProps['textField'], + MultiInputTimeRangeFieldSlotProps['textField'], {}, MultiInputTimeRangeFieldProps & { position: RangePosition; diff --git a/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.types.ts b/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.types.ts index a9fcc0831311..08708712d12d 100644 --- a/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.types.ts +++ b/packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.types.ts @@ -1,8 +1,10 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import Typography from '@mui/material/Typography'; -import Stack, { StackProps } from '@mui/material/Stack'; -import TextField from '@mui/material/TextField'; +import type { TypographyProps } from '@mui/material/Typography'; +import type { StackProps } from '@mui/material/Stack'; +import type { TextFieldProps } from '@mui/material/TextField'; +import { FieldOwnerState } from '@mui/x-date-pickers/models'; +import { SlotComponentPropsFromProps } from '@mui/x-internals/types'; +import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField'; import { UseTimeRangeFieldProps } from '../internals/models/timeRange'; import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types'; import { MultiInputFieldRefs, MultiInputRangeFieldClasses, RangePosition } from '../models'; @@ -49,7 +51,7 @@ export interface MultiInputTimeRangeFieldProps< * The props used for each component slot. * @default {} */ - slotProps?: MultiInputTimeRangeFieldSlotProps; + slotProps?: MultiInputTimeRangeFieldSlotProps; } export interface MultiInputTimeRangeFieldSlots { @@ -71,24 +73,14 @@ export interface MultiInputTimeRangeFieldSlots { separator?: React.ElementType; } -export interface MultiInputTimeRangeFieldSlotProps< - TEnableAccessibleFieldDOMStructure extends boolean, -> { - root?: SlotComponentProps< - typeof Stack, - {}, - MultiInputTimeRangeFieldProps - >; - textField?: SlotComponentProps< - typeof TextField, +export interface MultiInputTimeRangeFieldSlotProps { + root?: SlotComponentPropsFromProps; + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - MultiInputTimeRangeFieldProps & { + FieldOwnerState & { position: RangePosition; } >; - separator?: SlotComponentProps< - typeof Typography, - {}, - MultiInputTimeRangeFieldProps - >; + separator?: SlotComponentPropsFromProps; } diff --git a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.tsx b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.tsx index 02f127c0c715..1d1e79f63d3f 100644 --- a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.tsx +++ b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.tsx @@ -6,7 +6,10 @@ import { useThemeProps } from '@mui/material/styles'; import useSlotProps from '@mui/utils/useSlotProps'; import { refType } from '@mui/utils'; import { useClearableField } from '@mui/x-date-pickers/hooks'; -import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals'; +import { + convertFieldResponseIntoMuiTextFieldProps, + useFieldOwnerState, +} from '@mui/x-date-pickers/internals'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import { SingleInputDateRangeFieldProps } from './SingleInputDateRangeField.types'; import { useSingleInputDateRangeField } from './useSingleInputDateRangeField'; @@ -40,7 +43,7 @@ const SingleInputDateRangeField = React.forwardRef(function SingleInputDateRange const { slots, slotProps, InputProps, inputProps, ...other } = themeProps; - const ownerState = themeProps; + const ownerState = useFieldOwnerState(themeProps); const TextField = slots?.textField ?? diff --git a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.types.ts b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.types.ts index da88995ac304..bd7ceae3cfaa 100644 --- a/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.types.ts +++ b/packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.types.ts @@ -1,8 +1,9 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import TextField from '@mui/material/TextField'; +import type { TextFieldProps } from '@mui/material/TextField'; import { UseFieldInternalProps, PickerRangeValue } from '@mui/x-date-pickers/internals'; -import { BuiltInFieldTextFieldProps } from '@mui/x-date-pickers/models'; +import { BuiltInFieldTextFieldProps, FieldOwnerState } from '@mui/x-date-pickers/models'; +import { SlotComponentPropsFromProps } from '@mui/x-internals/types'; +import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField'; import { ExportedUseClearableFieldProps, UseClearableFieldSlots, @@ -44,23 +45,21 @@ export type SingleInputDateRangeFieldProps< * The props used for each component slot. * @default {} */ - slotProps?: SingleInputDateRangeFieldSlotProps; + slotProps?: SingleInputDateRangeFieldSlotProps; }; export interface SingleInputDateRangeFieldSlots extends UseClearableFieldSlots { /** * Form control with an input to render the value. - * @default TextField from '@mui/material' or PickersTextField if `enableAccessibleFieldDOMStructure` is `true`. + * @default , or from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`. */ textField?: React.ElementType; } -export interface SingleInputDateRangeFieldSlotProps< - TEnableAccessibleFieldDOMStructure extends boolean, -> extends UseClearableFieldSlotProps { - textField?: SlotComponentProps< - typeof TextField, +export interface SingleInputDateRangeFieldSlotProps extends UseClearableFieldSlotProps { + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - SingleInputDateRangeFieldProps + FieldOwnerState >; } diff --git a/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.tsx b/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.tsx index 1c3a0b1469dd..c8fcbda01693 100644 --- a/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.tsx +++ b/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.tsx @@ -2,7 +2,10 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import MuiTextField from '@mui/material/TextField'; -import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals'; +import { + convertFieldResponseIntoMuiTextFieldProps, + useFieldOwnerState, +} from '@mui/x-date-pickers/internals'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import { useThemeProps } from '@mui/material/styles'; import { refType } from '@mui/utils'; @@ -40,7 +43,7 @@ const SingleInputDateTimeRangeField = React.forwardRef(function SingleInputDateT const { slots, slotProps, InputProps, inputProps, ...other } = themeProps; - const ownerState = themeProps; + const ownerState = useFieldOwnerState(themeProps); const TextField = slots?.textField ?? diff --git a/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.ts b/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.ts index 6632d68fc3eb..24cdd359e2b8 100644 --- a/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.ts +++ b/packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.ts @@ -1,8 +1,9 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import TextField from '@mui/material/TextField'; +import type { TextFieldProps } from '@mui/material/TextField'; import { UseFieldInternalProps, PickerRangeValue } from '@mui/x-date-pickers/internals'; -import { BuiltInFieldTextFieldProps } from '@mui/x-date-pickers/models'; +import { BuiltInFieldTextFieldProps, FieldOwnerState } from '@mui/x-date-pickers/models'; +import { SlotComponentPropsFromProps } from '@mui/x-internals/types'; +import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField'; import { ExportedUseClearableFieldProps, UseClearableFieldSlots, @@ -41,23 +42,21 @@ export type SingleInputDateTimeRangeFieldProps< * The props used for each component slot. * @default {} */ - slotProps?: SingleInputDateTimeRangeFieldSlotProps; + slotProps?: SingleInputDateTimeRangeFieldSlotProps; }; export interface SingleInputDateTimeRangeFieldSlots extends UseClearableFieldSlots { /** * Form control with an input to render the value. - * @default TextField from '@mui/material' or PickersTextField if `enableAccessibleFieldDOMStructure` is `true`. + * @default , or from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`. */ textField?: React.ElementType; } -export interface SingleInputDateTimeRangeFieldSlotProps< - TEnableAccessibleFieldDOMStructure extends boolean, -> extends UseClearableFieldSlotProps { - textField?: SlotComponentProps< - typeof TextField, +export interface SingleInputDateTimeRangeFieldSlotProps extends UseClearableFieldSlotProps { + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - SingleInputDateTimeRangeFieldProps + FieldOwnerState >; } diff --git a/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.tsx b/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.tsx index ff5b9d8524cd..51996cc9b379 100644 --- a/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.tsx +++ b/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.tsx @@ -3,7 +3,10 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import MuiTextField from '@mui/material/TextField'; import { useClearableField } from '@mui/x-date-pickers/hooks'; -import { convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals'; +import { + convertFieldResponseIntoMuiTextFieldProps, + useFieldOwnerState, +} from '@mui/x-date-pickers/internals'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import { useThemeProps } from '@mui/material/styles'; import useSlotProps from '@mui/utils/useSlotProps'; @@ -40,7 +43,7 @@ const SingleInputTimeRangeField = React.forwardRef(function SingleInputTimeRange const { slots, slotProps, InputProps, inputProps, ...other } = themeProps; - const ownerState = themeProps; + const ownerState = useFieldOwnerState(themeProps); const TextField = slots?.textField ?? diff --git a/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.types.ts b/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.types.ts index 1cc0fa3fd483..be3da1043afe 100644 --- a/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.types.ts +++ b/packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.types.ts @@ -1,8 +1,9 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import TextField from '@mui/material/TextField'; +import type { TextFieldProps } from '@mui/material/TextField'; import { PickerRangeValue, UseFieldInternalProps } from '@mui/x-date-pickers/internals'; -import { BuiltInFieldTextFieldProps } from '@mui/x-date-pickers/models'; +import { BuiltInFieldTextFieldProps, FieldOwnerState } from '@mui/x-date-pickers/models'; +import { SlotComponentPropsFromProps } from '@mui/x-internals/types'; +import { PickersTextFieldProps } from '@mui/x-date-pickers/PickersTextField'; import { ExportedUseClearableFieldProps, UseClearableFieldSlots, @@ -41,23 +42,21 @@ export type SingleInputTimeRangeFieldProps< * The props used for each component slot. * @default {} */ - slotProps?: SingleInputTimeRangeFieldSlotProps; + slotProps?: SingleInputTimeRangeFieldSlotProps; }; export interface SingleInputTimeRangeFieldSlots extends UseClearableFieldSlots { /** * Form control with an input to render the value. - * @default TextField from '@mui/material' or PickersTextField if `enableAccessibleFieldDOMStructure` is `true`. + * @default , or from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`. */ textField?: React.ElementType; } -export interface SingleInputTimeRangeFieldSlotProps< - TEnableAccessibleFieldDOMStructure extends boolean, -> extends UseClearableFieldSlotProps { - textField?: SlotComponentProps< - typeof TextField, +export interface SingleInputTimeRangeFieldSlotProps extends UseClearableFieldSlotProps { + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - SingleInputTimeRangeFieldProps + FieldOwnerState >; } diff --git a/packages/x-date-pickers-pro/src/internals/hooks/useEnrichedRangePickerFieldProps.ts b/packages/x-date-pickers-pro/src/internals/hooks/useEnrichedRangePickerFieldProps.ts index 311e018ce3c0..0ea2b2e4a893 100644 --- a/packages/x-date-pickers-pro/src/internals/hooks/useEnrichedRangePickerFieldProps.ts +++ b/packages/x-date-pickers-pro/src/internals/hooks/useEnrichedRangePickerFieldProps.ts @@ -6,7 +6,12 @@ import resolveComponentProps from '@mui/utils/resolveComponentProps'; import useEventCallback from '@mui/utils/useEventCallback'; import useForkRef from '@mui/utils/useForkRef'; import { SlotComponentPropsFromProps } from '@mui/x-internals/types'; -import { FieldSelectedSections, FieldRef, PickerOwnerState } from '@mui/x-date-pickers/models'; +import { + FieldSelectedSections, + FieldRef, + PickerOwnerState, + FieldOwnerState, +} from '@mui/x-date-pickers/models'; import { UseClearableFieldSlots, UseClearableFieldSlotProps, @@ -28,7 +33,6 @@ import { RangeFieldSection, RangePosition, FieldType, - UseDateRangeFieldProps, PickerRangeFieldSlotProps, } from '../../models'; import { UseRangePositionResponse } from './useRangePosition'; @@ -65,12 +69,12 @@ export interface RangePickerFieldSlotProps; - fieldRoot?: SlotComponentProps>; - fieldSeparator?: SlotComponentProps>; + fieldRoot?: SlotComponentProps; + fieldSeparator?: SlotComponentProps; textField?: SlotComponentProps< typeof PickersTextField, {}, - UseDateRangeFieldProps & { position?: RangePosition } + FieldOwnerState & { position?: RangePosition } >; } diff --git a/packages/x-date-pickers-pro/src/internals/models/fields.ts b/packages/x-date-pickers-pro/src/internals/models/fields.ts index 79a498efbd54..4c058daf7bb7 100644 --- a/packages/x-date-pickers-pro/src/internals/models/fields.ts +++ b/packages/x-date-pickers-pro/src/internals/models/fields.ts @@ -2,7 +2,7 @@ import { SxProps } from '@mui/material/styles'; import { SlotComponentProps } from '@mui/utils'; import { MakeRequired } from '@mui/x-internals/types'; import { UseFieldInternalProps } from '@mui/x-date-pickers/internals'; -import { FieldSection } from '@mui/x-date-pickers/models'; +import { FieldOwnerState, FieldSection } from '@mui/x-date-pickers/models'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import type { MultiInputFieldRefs, @@ -47,15 +47,11 @@ export interface BaseMultiInputFieldProps< textField?: React.ElementType; }; slotProps?: { - root?: SlotComponentProps< - React.ElementType, - {}, - Record - >; + root?: SlotComponentProps, {}, FieldOwnerState>; textField?: SlotComponentProps< typeof PickersTextField, {}, - { position?: RangePosition } & Record + FieldOwnerState & { position?: RangePosition } >; }; } diff --git a/packages/x-date-pickers/src/DateField/DateField.tsx b/packages/x-date-pickers/src/DateField/DateField.tsx index 0a79fa946a2f..d676e85b1968 100644 --- a/packages/x-date-pickers/src/DateField/DateField.tsx +++ b/packages/x-date-pickers/src/DateField/DateField.tsx @@ -10,6 +10,7 @@ import { useDateField } from './useDateField'; import { useClearableField } from '../hooks'; import { PickersTextField } from '../PickersTextField'; import { convertFieldResponseIntoMuiTextFieldProps } from '../internals/utils/convertFieldResponseIntoMuiTextFieldProps'; +import { useFieldOwnerState } from '../internals/hooks/useFieldOwnerState'; type DateFieldComponent = (( props: DateFieldProps & React.RefAttributes, @@ -35,7 +36,7 @@ const DateField = React.forwardRef(function DateField< const { slots, slotProps, InputProps, inputProps, ...other } = themeProps; - const ownerState = themeProps; + const ownerState = useFieldOwnerState(themeProps); const TextField = slots?.textField ?? diff --git a/packages/x-date-pickers/src/DateField/DateField.types.ts b/packages/x-date-pickers/src/DateField/DateField.types.ts index 3a7c21470f5b..6969a2d52bb0 100644 --- a/packages/x-date-pickers/src/DateField/DateField.types.ts +++ b/packages/x-date-pickers/src/DateField/DateField.types.ts @@ -1,7 +1,6 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import { MakeOptional } from '@mui/x-internals/types'; -import TextField from '@mui/material/TextField'; +import type { TextFieldProps } from '@mui/material/TextField'; +import { MakeOptional, SlotComponentPropsFromProps } from '@mui/x-internals/types'; import { ExportedUseClearableFieldProps, UseClearableFieldSlots, @@ -12,9 +11,11 @@ import { FieldSection, PickerValidDate, BuiltInFieldTextFieldProps, + FieldOwnerState, } from '../models'; import { UseFieldInternalProps } from '../internals/hooks/useField'; import { ExportedValidateDateProps } from '../validation/validateDate'; +import { PickersTextFieldProps } from '../PickersTextField'; export interface UseDateFieldProps extends MakeOptional< @@ -46,7 +47,7 @@ export type DateFieldProps; + slotProps?: DateFieldSlotProps; }; export type DateFieldOwnerState = @@ -55,16 +56,15 @@ export type DateFieldOwnerState, or from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`. */ textField?: React.ElementType; } -export interface DateFieldSlotProps - extends UseClearableFieldSlotProps { - textField?: SlotComponentProps< - typeof TextField, +export interface DateFieldSlotProps extends UseClearableFieldSlotProps { + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - DateFieldOwnerState + FieldOwnerState >; } diff --git a/packages/x-date-pickers/src/DateTimeField/DateTimeField.tsx b/packages/x-date-pickers/src/DateTimeField/DateTimeField.tsx index 20002236886f..9ef2155d91ef 100644 --- a/packages/x-date-pickers/src/DateTimeField/DateTimeField.tsx +++ b/packages/x-date-pickers/src/DateTimeField/DateTimeField.tsx @@ -10,6 +10,7 @@ import { useDateTimeField } from './useDateTimeField'; import { useClearableField } from '../hooks'; import { PickersTextField } from '../PickersTextField'; import { convertFieldResponseIntoMuiTextFieldProps } from '../internals/utils/convertFieldResponseIntoMuiTextFieldProps'; +import { useFieldOwnerState } from '../internals/hooks/useFieldOwnerState'; type DateTimeFieldComponent = (( props: DateTimeFieldProps & @@ -39,7 +40,7 @@ const DateTimeField = React.forwardRef(function DateTimeField< const { slots, slotProps, InputProps, inputProps, ...other } = themeProps; - const ownerState = themeProps; + const ownerState = useFieldOwnerState(themeProps); const TextField = slots?.textField ?? diff --git a/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts b/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts index b306ed6dbd2b..3bbaea62e57b 100644 --- a/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts +++ b/packages/x-date-pickers/src/DateTimeField/DateTimeField.types.ts @@ -1,12 +1,12 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import { MakeOptional } from '@mui/x-internals/types'; -import TextField from '@mui/material/TextField'; +import type { TextFieldProps } from '@mui/material/TextField'; +import { MakeOptional, SlotComponentPropsFromProps } from '@mui/x-internals/types'; import { DateTimeValidationError, FieldSection, PickerValidDate, BuiltInFieldTextFieldProps, + FieldOwnerState, } from '../models'; import { UseFieldInternalProps } from '../internals/hooks/useField'; import { @@ -16,6 +16,7 @@ import { } from '../hooks/useClearableField'; import { ExportedValidateDateTimeProps } from '../validation/validateDateTime'; import { AmPmProps } from '../internals/models/props/time'; +import { PickersTextFieldProps } from '../PickersTextField'; export interface UseDateTimeFieldProps extends MakeOptional< @@ -48,25 +49,21 @@ export type DateTimeFieldProps; + slotProps?: DateTimeFieldSlotProps; }; -export type DateTimeFieldOwnerState = - DateTimeFieldProps; - export interface DateTimeFieldSlots extends UseClearableFieldSlots { /** * Form control with an input to render the value. - * @default TextField from '@mui/material' or PickersTextField if `enableAccessibleFieldDOMStructure` is `true`. + * @default , or from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`. */ textField?: React.ElementType; } -export interface DateTimeFieldSlotProps - extends UseClearableFieldSlotProps { - textField?: SlotComponentProps< - typeof TextField, +export interface DateTimeFieldSlotProps extends UseClearableFieldSlotProps { + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - DateTimeFieldOwnerState + FieldOwnerState >; } diff --git a/packages/x-date-pickers/src/TimeField/TimeField.tsx b/packages/x-date-pickers/src/TimeField/TimeField.tsx index b84ff450fa90..1b3a062241cd 100644 --- a/packages/x-date-pickers/src/TimeField/TimeField.tsx +++ b/packages/x-date-pickers/src/TimeField/TimeField.tsx @@ -10,6 +10,7 @@ import { useTimeField } from './useTimeField'; import { useClearableField } from '../hooks'; import { PickersTextField } from '../PickersTextField'; import { convertFieldResponseIntoMuiTextFieldProps } from '../internals/utils/convertFieldResponseIntoMuiTextFieldProps'; +import { useFieldOwnerState } from '../internals/hooks/useFieldOwnerState'; type TimeFieldComponent = (( props: TimeFieldProps & React.RefAttributes, @@ -35,7 +36,7 @@ const TimeField = React.forwardRef(function TimeField< const { slots, slotProps, InputProps, inputProps, ...other } = themeProps; - const ownerState = themeProps; + const ownerState = useFieldOwnerState(themeProps); const TextField = slots?.textField ?? diff --git a/packages/x-date-pickers/src/TimeField/TimeField.types.ts b/packages/x-date-pickers/src/TimeField/TimeField.types.ts index af41f53ee623..8982b49df1b0 100644 --- a/packages/x-date-pickers/src/TimeField/TimeField.types.ts +++ b/packages/x-date-pickers/src/TimeField/TimeField.types.ts @@ -1,13 +1,13 @@ import * as React from 'react'; -import { SlotComponentProps } from '@mui/utils'; -import { MakeOptional } from '@mui/x-internals/types'; -import TextField from '@mui/material/TextField'; +import type { TextFieldProps } from '@mui/material/TextField'; +import { MakeOptional, SlotComponentPropsFromProps } from '@mui/x-internals/types'; import { UseFieldInternalProps } from '../internals/hooks/useField'; import { FieldSection, PickerValidDate, TimeValidationError, BuiltInFieldTextFieldProps, + FieldOwnerState, } from '../models'; import { ExportedUseClearableFieldProps, @@ -16,6 +16,7 @@ import { } from '../hooks/useClearableField'; import { ExportedValidateTimeProps } from '../validation/validateTime'; import { AmPmProps } from '../internals/models/props/time'; +import { PickersTextFieldProps } from '../PickersTextField'; export interface UseTimeFieldProps extends MakeOptional< @@ -48,25 +49,21 @@ export type TimeFieldProps; + slotProps?: TimeFieldSlotProps; }; -export type TimeFieldOwnerState = - TimeFieldProps; - export interface TimeFieldSlots extends UseClearableFieldSlots { /** * Form control with an input to render the value. - * @default TextField from '@mui/material' or PickersTextField if `enableAccessibleFieldDOMStructure` is `true`. + * @default , or from '@mui/material' if `enableAccessibleFieldDOMStructure` is `false`. */ textField?: React.ElementType; } -export interface TimeFieldSlotProps - extends UseClearableFieldSlotProps { - textField?: SlotComponentProps< - typeof TextField, +export interface TimeFieldSlotProps extends UseClearableFieldSlotProps { + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, {}, - TimeFieldOwnerState + FieldOwnerState >; } diff --git a/packages/x-date-pickers/src/internals/hooks/useDesktopPicker/useDesktopPicker.types.ts b/packages/x-date-pickers/src/internals/hooks/useDesktopPicker/useDesktopPicker.types.ts index 8aead242e00d..d39be72789b6 100644 --- a/packages/x-date-pickers/src/internals/hooks/useDesktopPicker/useDesktopPicker.types.ts +++ b/packages/x-date-pickers/src/internals/hooks/useDesktopPicker/useDesktopPicker.types.ts @@ -1,8 +1,7 @@ import * as React from 'react'; -import IconButton, { IconButtonProps } from '@mui/material/IconButton'; -import { InputAdornmentProps } from '@mui/material/InputAdornment'; -import TextField from '@mui/material/TextField'; -import { SlotComponentProps } from '@mui/utils'; +import type { IconButtonProps } from '@mui/material/IconButton'; +import type { InputAdornmentProps } from '@mui/material/InputAdornment'; +import type { TextFieldProps } from '@mui/material/TextField'; import { MakeRequired, SlotComponentPropsFromProps } from '@mui/x-internals/types'; import { BaseNonStaticPickerProps, @@ -12,6 +11,7 @@ import { import { PickersPopperSlots, PickersPopperSlotProps } from '../../components/PickersPopper'; import { UsePickerParams } from '../usePicker'; import { + FieldOwnerState, FieldSection, PickerFieldSlotProps, PickerOwnerState, @@ -29,6 +29,7 @@ import { UseClearableFieldSlots, UseClearableFieldSlotProps, } from '../../../hooks/useClearableField'; +import { PickersTextFieldProps } from '../../../PickersTextField'; export interface UseDesktopPickerSlots extends Pick< @@ -79,9 +80,13 @@ export interface ExportedUseDesktopPickerSlotProps< {}, PickerOwnerState >; - textField?: SlotComponentProps>; + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, + {}, + FieldOwnerState + >; inputAdornment?: SlotComponentPropsFromProps; - openPickerButton?: SlotComponentProps; + openPickerButton?: SlotComponentPropsFromProps; openPickerIcon?: SlotComponentPropsFromProps, {}, PickerOwnerState>; } diff --git a/packages/x-date-pickers/src/internals/hooks/useFieldOwnerState.ts b/packages/x-date-pickers/src/internals/hooks/useFieldOwnerState.ts new file mode 100644 index 000000000000..bc1c326465dd --- /dev/null +++ b/packages/x-date-pickers/src/internals/hooks/useFieldOwnerState.ts @@ -0,0 +1,19 @@ +import * as React from 'react'; +import { FieldOwnerState } from '../../models'; +import { FormProps } from '../models'; +import { usePickerPrivateContext } from './usePickerPrivateContext'; + +export function useFieldOwnerState(parameters: UseFieldOwnerStateParameters) { + const { ownerState: pickerOwnerState } = usePickerPrivateContext(); + + return React.useMemo( + () => ({ + ...pickerOwnerState, + isFieldDisabled: parameters.disabled ?? false, + isFieldReadOnly: parameters.readOnly ?? false, + }), + [pickerOwnerState, parameters.disabled, parameters.readOnly], + ); +} + +interface UseFieldOwnerStateParameters extends FormProps {} diff --git a/packages/x-date-pickers/src/internals/hooks/useMobilePicker/useMobilePicker.types.ts b/packages/x-date-pickers/src/internals/hooks/useMobilePicker/useMobilePicker.types.ts index a811500a7a67..ad2c835ec0d6 100644 --- a/packages/x-date-pickers/src/internals/hooks/useMobilePicker/useMobilePicker.types.ts +++ b/packages/x-date-pickers/src/internals/hooks/useMobilePicker/useMobilePicker.types.ts @@ -1,6 +1,5 @@ import * as React from 'react'; -import TextField from '@mui/material/TextField'; -import { SlotComponentProps } from '@mui/utils'; +import type { TextFieldProps } from '@mui/material/TextField'; import { MakeRequired, SlotComponentPropsFromProps } from '@mui/x-internals/types'; import { BaseNonStaticPickerProps, @@ -13,6 +12,7 @@ import { } from '../../components/PickersModalDialog'; import { UsePickerParams } from '../usePicker'; import { + FieldOwnerState, FieldSection, PickerFieldSlotProps, PickerOwnerState, @@ -26,6 +26,7 @@ import { import { UsePickerValueNonStaticProps } from '../usePicker/usePickerValue.types'; import { UsePickerViewsNonStaticProps, UsePickerViewsProps } from '../usePicker/usePickerViews'; import { DateOrTimeViewWithMeridiem } from '../../models'; +import { PickersTextFieldProps } from '../../../PickersTextField'; export interface UseMobilePickerSlots extends PickersModalDialogSlots, @@ -51,7 +52,11 @@ export interface ExportedUseMobilePickerSlotProps< {}, PickerOwnerState >; - textField?: SlotComponentProps>; + textField?: SlotComponentPropsFromProps< + PickersTextFieldProps | TextFieldProps, + {}, + FieldOwnerState + >; } export interface UseMobilePickerSlotProps< diff --git a/packages/x-date-pickers/src/internals/index.ts b/packages/x-date-pickers/src/internals/index.ts index 58791c5d2476..10f9aedf54fd 100644 --- a/packages/x-date-pickers/src/internals/index.ts +++ b/packages/x-date-pickers/src/internals/index.ts @@ -64,6 +64,7 @@ export type { FieldChangeHandler, FieldChangeHandlerContext, } from './hooks/useField'; +export { useFieldOwnerState } from './hooks/useFieldOwnerState'; export type { MobileOnlyPickerProps } from './hooks/useMobilePicker'; export { usePicker } from './hooks/usePicker'; export type { diff --git a/packages/x-date-pickers/src/models/fields.ts b/packages/x-date-pickers/src/models/fields.ts index aaff817b403e..da6211729664 100644 --- a/packages/x-date-pickers/src/models/fields.ts +++ b/packages/x-date-pickers/src/models/fields.ts @@ -8,6 +8,7 @@ import { ExportedPickersSectionListProps } from '../PickersSectionList'; import type { UseFieldInternalProps, UseFieldResponse } from '../internals/hooks/useField'; import type { PickersTextFieldProps } from '../PickersTextField'; import { BaseForwardedSingleInputFieldProps } from '../internals/models'; +import { PickerOwnerState } from './pickers'; // Update PickersComponentAgnosticLocaleText -> viewNames when adding new entries export type FieldSectionType = @@ -117,6 +118,17 @@ export interface FieldRef { export type FieldSelectedSections = number | FieldSectionType | null | 'all'; +export interface FieldOwnerState extends PickerOwnerState { + /** + * `true` if the field is disabled, `false` otherwise. + */ + isFieldDisabled: boolean; + /** + * `true` if the field is read-only, `false` otherwise. + */ + isFieldReadOnly: boolean; +} + /** * Props the prop `slotProps.field` of a picker can receive. */ diff --git a/scripts/x-date-pickers-pro.exports.json b/scripts/x-date-pickers-pro.exports.json index 1ea478a0b8c3..000dcf04cb5c 100644 --- a/scripts/x-date-pickers-pro.exports.json +++ b/scripts/x-date-pickers-pro.exports.json @@ -157,6 +157,7 @@ { "name": "ExportedUseClearableFieldProps", "kind": "Interface" }, { "name": "extractValidationProps", "kind": "Variable" }, { "name": "FieldFormatTokenMap", "kind": "TypeAlias" }, + { "name": "FieldOwnerState", "kind": "Interface" }, { "name": "FieldRef", "kind": "Interface" }, { "name": "FieldSection", "kind": "Interface" }, { "name": "FieldSectionContentType", "kind": "TypeAlias" }, diff --git a/scripts/x-date-pickers.exports.json b/scripts/x-date-pickers.exports.json index 0a7b338d04d4..76738c3e2dca 100644 --- a/scripts/x-date-pickers.exports.json +++ b/scripts/x-date-pickers.exports.json @@ -105,6 +105,7 @@ { "name": "ExportedUseClearableFieldProps", "kind": "Interface" }, { "name": "extractValidationProps", "kind": "Variable" }, { "name": "FieldFormatTokenMap", "kind": "TypeAlias" }, + { "name": "FieldOwnerState", "kind": "Interface" }, { "name": "FieldRef", "kind": "Interface" }, { "name": "FieldSection", "kind": "Interface" }, { "name": "FieldSectionContentType", "kind": "TypeAlias" },