Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -230,7 +230,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 @@ -274,4 +281,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<Variant extends TextFieldVariants>(
props: {
/**
* The variant to use.
* @default 'outlined'
*/
variant?: Variant;
} & 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
30 changes: 0 additions & 30 deletions packages/mui-material/test/typescript/hoc-interop.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,11 @@
* It's a common pattern to use some form of Pick or Omit in hocs which don't have
* a desired outcome when operating on union types.
*
* We use our TextField component since it has a union type as props
*
* See https://github.com/Microsoft/TypeScript/issues/28339 for in-depth discussion
*/
import { Button } from '@mui/material';
import { createStyles, withStyles } from '@mui/styles';
import TextField, { TextFieldProps } from '@mui/material/TextField';
import emotionStyled from '@emotion/styled';
import * as React from 'react';
import styled from 'styled-components';

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

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

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

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

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