Skip to content

Commit a357d39

Browse files
committed
change implementation
1 parent 2480153 commit a357d39

File tree

2 files changed

+31
-38
lines changed

2 files changed

+31
-38
lines changed

packages/mui-material/src/Select/Select.d.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,10 @@ export interface OutlinedSelectProps extends Omit<OutlinedInputProps, 'value' |
177177

178178
export type SelectVariants = 'outlined' | 'standard' | 'filled';
179179

180-
export type SelectProps<
181-
Value = unknown,
182-
Variant extends SelectVariants = SelectVariants,
183-
> = BaseSelectProps<Value> &
184-
(Variant extends 'filled'
185-
? FilledSelectProps
186-
: Variant extends 'standard'
187-
? StandardSelectProps
188-
: OutlinedSelectProps);
180+
export type SelectProps<Value = unknown> =
181+
| (FilledSelectProps & BaseSelectProps<Value>)
182+
| (StandardSelectProps & BaseSelectProps<Value>)
183+
| (OutlinedSelectProps & BaseSelectProps<Value>);
189184

190185
/**
191186
*
@@ -198,14 +193,8 @@ export type SelectProps<
198193
* - [Select API](https://mui.com/material-ui/api/select/)
199194
* - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
200195
*/
201-
export default function Select<Value = unknown, Variant extends SelectVariants = 'outlined'>(
202-
props: {
203-
/**
204-
* The variant to use.
205-
* @default 'outlined'
206-
*/
207-
variant?: Variant;
208-
} & SelectProps<Value, Variant>,
196+
export default function Select<Value = unknown>(
197+
props: SelectProps<Value>,
209198
): JSX.Element & {
210199
muiName: string;
211200
};

packages/mui-material/src/Select/Select.spec.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,19 @@ function genericValueTest() {
7676
}}
7777
/>;
7878

79-
// @ts-expect-error
80-
<Select<number, 'filled'> />;
81-
// @ts-expect-error
82-
<Select<number, 'standard'> />;
83-
// @ts-expect-error
84-
<Select<number, 'standard'> variant="filled" />;
85-
// @ts-expect-error
86-
<Select<number, 'filled'> variant="standard" />;
87-
88-
<Select<number, 'outlined'> />;
89-
90-
<Select<number, 'filled'> variant="filled" />;
91-
<Select<number, 'outlined'> variant="outlined" />;
92-
<Select<number, 'standard'> variant="standard" />;
93-
9479
<Select variant="filled" />;
9580
<Select variant="standard" />;
9681
<Select variant="outlined" />;
9782
<Select />;
9883

84+
<Select variant="filled" hiddenLabel />;
85+
// @ts-expect-error hiddenLabel is not present in standard variant
86+
<Select variant="standard" hiddenLabel />;
87+
// @ts-expect-error hiddenLabel is not present in outlined variant
88+
<Select variant="outlined" hiddenLabel />;
89+
// @ts-expect-error hiddenLabel is not present in outlined variant
90+
<Select hiddenLabel />;
91+
9992
const defaultProps: SelectProps<number> = {};
10093
const outlinedProps: SelectProps<number> = {
10194
variant: 'outlined',
@@ -113,13 +106,7 @@ function genericValueTest() {
113106
<Select {...standardProps} />;
114107
<Select<number> {...outlinedProps} />;
115108
<Select<number> {...defaultProps} />;
116-
<Select<number, 'standard'> {...standardProps} />;
117-
// @ts-expect-error variant type mismatch
118109
<Select<number> {...filledProps} />;
119-
// @ts-expect-error variant type mismatch
120-
<Select<number, 'outlined'> {...filledProps} />;
121-
// @ts-expect-error variant type mismatch
122-
<Select<number, 'standard'> {...filledProps} />;
123110

124111
const rawDefaultProps: SelectProps = {};
125112
const rawOutlinedProps: SelectProps = {
@@ -140,6 +127,23 @@ function genericValueTest() {
140127
<Select {...filledProps} hiddenLabel />;
141128
// @ts-expect-error hiddenLabel is not present in standard variant
142129
<Select {...standardProps} hiddenLabel />;
130+
131+
interface OtherProps {
132+
otherProp?: number;
133+
}
134+
135+
const SelectWrapper1 = <Value = unknown,>(props: SelectProps<Value> & OtherProps) => {
136+
const { otherProp, ...materialSelectProps } = props;
137+
138+
return (
139+
// how to solve this:
140+
<Select<Value> {...materialSelectProps} />
141+
);
142+
};
143+
144+
<SelectWrapper1 />;
145+
<SelectWrapper1<number> variant="filled" hiddenLabel />;
146+
<SelectWrapper1 variant="filled" hiddenLabel />;
143147
}
144148

145149
type Options<T> = { text: string; value: T } | T;

0 commit comments

Comments
 (0)