Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
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
2 changes: 2 additions & 0 deletions docs/pages/material-ui/api/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"input",
"inputSizeSmall",
"inputMultiline",
"inputAdornedStart",
"inputAdornedEnd",
"inputTypeSearch"
],
"globalClasses": { "focused": "Mui-focused", "disabled": "Mui-disabled", "error": "Mui-error" },
Expand Down
10 changes: 10 additions & 0 deletions docs/translations/api-docs/input/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@
"nodeName": "the input element",
"conditions": "<code>multiline={true}</code>"
},
"inputAdornedStart": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the input element",
"conditions": "<code>startAdornment</code> is provided"
},
"inputAdornedEnd": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the input element",
"conditions": "<code>endAdornment</code> is provided"
},
"inputTypeSearch": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the input element",
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-material/src/Input/inputClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export interface InputClasses {
inputSizeSmall: string;
/** Styles applied to the input element if `multiline={true}`. */
inputMultiline: string;
/** Styles applied to the input element if `startAdornment` is provided. */
inputAdornedStart: string;
/** Styles applied to the input element if `endAdornment` is provided. */
inputAdornedEnd: string;
/** Styles applied to the input element if `type="search"`. */
inputTypeSearch: string;
}
Expand Down
19 changes: 17 additions & 2 deletions packages/mui-material/src/TextField/TextField.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,14 @@ export interface OutlinedTextFieldProps extends BaseTextFieldProps {
InputProps?: Partial<OutlinedInputProps>;
}

export type TextFieldProps = StandardTextFieldProps | FilledTextFieldProps | OutlinedTextFieldProps;
export type TextFieldVariants = 'outlined' | 'standard' | 'filled';

export type TextFieldProps<Variant extends TextFieldVariants = TextFieldVariants> =
Variant extends 'filled'
? FilledTextFieldProps
: Variant extends 'standard'
? StandardTextFieldProps
: OutlinedTextFieldProps;

/**
* The `TextField` is a convenience wrapper for the most common cases (80%).
Expand Down Expand Up @@ -270,4 +277,12 @@ export type TextFieldProps = StandardTextFieldProps | FilledTextFieldProps | Out
* - [TextField API](https://mui.com/material-ui/api/text-field/)
* - inherits [FormControl API](https://mui.com/material-ui/api/form-control/)
*/
export default function TextField(props: TextFieldProps): JSX.Element;
export default function TextField<V extends TextFieldVariants>(
props: {
/**
* The variant to use.
* @default 'outlined'
*/
variant?: V;
} & Omit<TextFieldProps, 'variant'>,
): JSX.Element;
16 changes: 16 additions & 0 deletions packages/mui-material/src/TextField/TextField.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ import { expectType } from '@mui/types';
<TextField variant="standard" InputProps={{ classes: { inputTypeSearch: 'search-input' } }} />
);

const StandardInputAdorned = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests for #36862

<TextField
variant="standard"
InputProps={{
classes: { inputAdornedStart: 'search-input', inputAdornedEnd: 'search-input' },
}}
/>
);
const DefaultInputAdorned = (
<TextField
InputProps={{
classes: { inputAdornedStart: 'search-input', inputAdornedEnd: 'search-input' },
}}
/>
);

const outlinedInputTypeSearch = (
<TextField variant="outlined" InputProps={{ classes: { inputTypeSearch: 'search-input' } }} />
);
Expand Down
16 changes: 10 additions & 6 deletions packages/mui-material/test/typescript/hoc-interop.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,29 @@ const filledProps = {
InputProps: { classes: { inputAdornedStart: 'adorned' } },
};

const outlinedProps = {
InputProps: { classes: { inputAdornedStart: 'adorned' } },
};

// baseline behavior
<TextField variant="filled" {...filledProps} />;
// @ts-expect-error
<TextField {...filledProps} />; // desired to throw

<TextField {...outlinedProps} />;

// styled
{
const StyledTextField = styled(TextField)``;
<StyledTextField variant="filled" {...filledProps} />; // desired to pass
// @ts-expect-error
<StyledTextField {...filledProps} />; // undesired, should throw

<StyledTextField {...outlinedProps} />;
}

// @emotion/styled
{
const StyledTextField = emotionStyled(TextField)``;
<StyledTextField variant="filled" {...filledProps} />;
// @ts-expect-error
<StyledTextField {...filledProps} />; // desired to throw

<StyledTextField {...outlinedProps} />;
}

// https://github.com/mui/material-ui/issues/14586
Expand Down