Skip to content

Commit 636740c

Browse files
committed
fix #41375
1 parent d7bda2a commit 636740c

File tree

3 files changed

+62
-17
lines changed

3 files changed

+62
-17
lines changed

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,15 @@ export type SelectProps<
188188
: OutlinedSelectProps);
189189

190190
interface SelectType {
191-
<Value, Variant extends 'filled' | 'standard'>(
192-
props: {
193-
/**
194-
* The variant to use.
195-
* @default 'outlined'
196-
*/
197-
variant: Variant;
198-
} & Omit<SelectProps<Value, Variant>, 'variant'>,
199-
): JSX.Element & {
200-
muiName: string;
201-
};
202-
<Value = unknown, Variant extends 'outlined' = 'outlined'>(
191+
<Value = unknown, Variant extends SelectVariants = 'outlined'>(
203192
props: {
204193
/**
205194
* The variant to use.
206195
* @default 'outlined'
207196
*/
208197
variant?: Variant;
209-
} & Omit<SelectProps<Value, Variant>, 'variant'>,
210-
): JSX.Element & {
211-
muiName: string;
212-
};
198+
} & SelectProps<Value, Variant>,
199+
): JSX.Element;
213200
}
214201
/**
215202
*

packages/mui-material/src/Select/Select.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ Select.propTypes /* remove-proptypes */ = {
279279
* The variant to use.
280280
* @default 'outlined'
281281
*/
282-
variant: PropTypes.oneOf(['filled', 'outlined', 'standard']),
282+
variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOf([
283+
'filled',
284+
'outlined',
285+
'standard',
286+
]),
283287
};
284288

285289
Select.muiName = 'Select';

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,57 @@ function genericValueTest() {
141141
// @ts-expect-error hiddenLabel is not present in standard variant
142142
<Select {...standardProps} hiddenLabel />;
143143
}
144+
145+
type Options<T> = { text: string; value: T } | T;
146+
147+
type Props<T> = (
148+
| {
149+
value: T;
150+
multiple?: false;
151+
onChange: (value: T) => void;
152+
}
153+
| {
154+
value: T[];
155+
multiple: true;
156+
onChange: (value: T[]) => void;
157+
}
158+
) & {
159+
options: Options<T>[];
160+
};
161+
162+
// test for https://github.com/mui/material-ui/issues/41375
163+
const AppSelect = <T extends string>(props: Props<T>) => {
164+
const getOptionText = (option: Options<T>) => {
165+
if (typeof option === 'object') {
166+
return option.text;
167+
}
168+
return option;
169+
};
170+
171+
const getOptionValue = (option: Options<T>) => {
172+
if (typeof option === 'object') {
173+
return option.value;
174+
}
175+
return option;
176+
};
177+
178+
return (
179+
<Select
180+
value={props.value}
181+
multiple={props.multiple}
182+
onChange={(event) => {
183+
if (props.multiple) {
184+
props.onChange(event.target.value as T[]);
185+
} else {
186+
props.onChange(event.target.value as T);
187+
}
188+
}}
189+
>
190+
{props.options.map((option, index) => (
191+
<MenuItem key={index} value={getOptionValue(option)}>
192+
{getOptionText(option)}
193+
</MenuItem>
194+
))}
195+
</Select>
196+
);
197+
};

0 commit comments

Comments
 (0)