Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Select] Fix variant type #41405

Merged
merged 10 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
49 changes: 38 additions & 11 deletions packages/mui-material/src/Select/Select.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,43 @@ export type SelectProps<
? StandardSelectProps
: OutlinedSelectProps);

interface SelectType {
<Value, Variant extends 'filled' | 'standard'>(
props: {
/**
* The variant to use.
* @default 'outlined'
*/
variant: Variant;
} & Omit<SelectProps<Value, Variant>, 'variant'>,
): JSX.Element & {
muiName: string;
};
<Value = unknown, Variant extends 'outlined' = 'outlined'>(
props: {
/**
* The variant to use.
* @default 'outlined'
*/
variant?: Variant;
} & Omit<SelectProps<Value, Variant>, 'variant'>,
): JSX.Element & {
muiName: string;
};
}
/**
*
* Demos:
*
* - [Select](https://mui.com/material-ui/react-select/)
*
* API:
*
* - [Select API](https://mui.com/material-ui/api/select/)
* - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
*/
declare const Select: SelectType;

/**
*
* Demos:
Expand All @@ -199,14 +236,4 @@ export type SelectProps<
* - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
*/

export default function Select<Value = unknown, Variant extends SelectVariants = 'outlined'>(
props: {
/**
* The variant to use.
* @default 'outlined'
*/
variant?: Variant;
} & Omit<SelectProps<Value, Variant>, 'variant'>,
): JSX.Element & {
muiName: string;
};
export default Select;
20 changes: 20 additions & 0 deletions packages/mui-material/src/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@ function genericValueTest() {
},
}}
/>;

// @ts-expect-error
<Select<number, 'filled'> />;
// @ts-expect-error
<Select<number, 'standard'> />;
// @ts-expect-error
<Select<number, 'standard'> variant="filled" />;
// @ts-expect-error
<Select<number, 'filled'> variant="standard" />;

<Select<number, 'outlined'> />;

<Select<number, 'filled'> variant="filled" />;
<Select<number, 'outlined'> variant="outlined" />;
<Select<number, 'standard'> variant="standard" />;

<Select variant="filled" />;
<Select variant="standard" />;
<Select variant="outlined" />;
<Select />;
}
Loading