Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add override types for other slots and module augmentation tests
  • Loading branch information
ZeeshanTamboli committed Nov 25, 2025
commit c979aba75014efffc8dcf37f6e0ff3d0354ec03c
28 changes: 24 additions & 4 deletions packages/mui-material/src/TextField/TextField.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export interface TextFieldSlots {
select: React.ElementType;
}

export interface TextFieldRootSlotPropsOverrides {}
export interface TextFieldInputSlotPropsOverrides {}
export interface TextFieldInputLabelSlotPropsOverrides {}
export interface TextFieldFormHelperTextSlotPropsOverrides {}
export interface TextFieldSelectSlotPropsOverrides {}

export type TextFieldSlotsAndSlotProps<InputPropsType> = CreateSlotsAndSlotProps<
TextFieldSlots,
Expand All @@ -59,17 +63,29 @@ export type TextFieldSlotsAndSlotProps<InputPropsType> = CreateSlotsAndSlotProps
* Props forwarded to the root slot.
* By default, the available props are based on the [FormControl](https://mui.com/material-ui/api/form-control/#props) component.
*/
root: SlotProps<React.ElementType<FormControlProps>, {}, TextFieldOwnerState>;
root: SlotProps<
React.ElementType<FormControlProps>,
TextFieldRootSlotPropsOverrides,
TextFieldOwnerState
>;
/**
* Props forwarded to the input slot.
* By default, the available props are based on the [Input](https://mui.com/material-ui/api/input/#props) component.
*/
input: SlotProps<React.ElementType<InputPropsType>, {}, TextFieldOwnerState>;
input: SlotProps<
React.ElementType<InputPropsType>,
TextFieldInputSlotPropsOverrides,
TextFieldOwnerState
>;
/**
* Props forwarded to the input label slot.
* By default, the available props are based on the [InputLabel](https://mui.com/material-ui/api/input-label/#props) component.
*/
inputLabel: SlotProps<React.ElementType<InputLabelProps>, {}, TextFieldOwnerState>;
inputLabel: SlotProps<
React.ElementType<InputLabelProps>,
TextFieldInputLabelSlotPropsOverrides,
TextFieldOwnerState
>;
/**
* Props forwarded to the html input slot.
* By default, the available props are based on the html input element.
Expand All @@ -88,7 +104,11 @@ export type TextFieldSlotsAndSlotProps<InputPropsType> = CreateSlotsAndSlotProps
* Props forwarded to the select slot.
* By default, the available props are based on the [Select](https://mui.com/material-ui/api/select/#props) component.
*/
select: SlotProps<React.ElementType<SelectProps>, {}, TextFieldOwnerState>;
select: SlotProps<
React.ElementType<SelectProps>,
TextFieldSelectSlotPropsOverrides,
TextFieldOwnerState
>;
}
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,41 @@ const theme = createTheme({
<TextField variant="filled" size="extraLarge">
Custom Size TextField
</TextField>;

declare module '@mui/material/TextField' {
interface TextFieldFormHelperTextSlotPropsOverrides {
'data-cy'?: string;
}
interface TextFieldRootSlotPropsOverrides {
customRootProp?: string;
}
interface TextFieldInputSlotPropsOverrides {
customInputProp?: string;
}
interface TextFieldInputLabelSlotPropsOverrides {
customInputLabelProp?: string;
}
interface TextFieldSelectSlotPropsOverrides {
customSelectProp?: string;
}
}

<TextField
slotProps={{
formHelperText: { 'data-cy': 'email-error' },
root: {
customRootProp: 'abc',
},
input: {
customInputProp: 'abc',
},
inputLabel: {
customInputLabelProp: 'abc',
},
select: {
customSelectProp: 'abc',
},
}}
>
Custom TextField
</TextField>;
Loading