File tree 2 files changed +65
-39
lines changed
packages/mui-material/src/Select
2 files changed +65
-39
lines changed Original file line number Diff line number Diff line change @@ -187,43 +187,6 @@ export type SelectProps<
187
187
? StandardSelectProps
188
188
: OutlinedSelectProps ) ;
189
189
190
- 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' > (
203
- props : {
204
- /**
205
- * The variant to use.
206
- * @default 'outlined'
207
- */
208
- variant ?: Variant ;
209
- } & Omit < SelectProps < Value , Variant > , 'variant' > ,
210
- ) : JSX . Element & {
211
- muiName : string ;
212
- } ;
213
- }
214
- /**
215
- *
216
- * Demos:
217
- *
218
- * - [Select](https://mui.com/material-ui/react-select/)
219
- *
220
- * API:
221
- *
222
- * - [Select API](https://mui.com/material-ui/api/select/)
223
- * - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
224
- */
225
- declare const Select : SelectType ;
226
-
227
190
/**
228
191
*
229
192
* Demos:
@@ -235,5 +198,14 @@ declare const Select: SelectType;
235
198
* - [Select API](https://mui.com/material-ui/api/select/)
236
199
* - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
237
200
*/
238
-
239
- export default Select ;
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 > ,
209
+ ) : JSX . Element & {
210
+ muiName : string ;
211
+ } ;
Original file line number Diff line number Diff line change @@ -141,3 +141,57 @@ function genericValueTest() {
141
141
// @ts -expect-error hiddenLabel is not present in standard variant
142
142
< Select { ...standardProps } hiddenLabel /> ;
143
143
}
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
+ } ;
You can’t perform that action at this time.
0 commit comments