File tree 3 files changed +62
-17
lines changed
packages/mui-material/src/Select
3 files changed +62
-17
lines changed Original file line number Diff line number Diff line change @@ -188,28 +188,15 @@ export type SelectProps<
188
188
: OutlinedSelectProps ) ;
189
189
190
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' > (
191
+ < Value = unknown , Variant extends SelectVariants = 'outlined' > (
203
192
props : {
204
193
/**
205
194
* The variant to use.
206
195
* @default 'outlined'
207
196
*/
208
197
variant ?: Variant ;
209
- } & Omit < SelectProps < Value , Variant > , 'variant' > ,
210
- ) : JSX . Element & {
211
- muiName : string ;
212
- } ;
198
+ } & SelectProps < Value , Variant > ,
199
+ ) : JSX . Element ;
213
200
}
214
201
/**
215
202
*
Original file line number Diff line number Diff line change @@ -279,7 +279,11 @@ Select.propTypes /* remove-proptypes */ = {
279
279
* The variant to use.
280
280
* @default 'outlined'
281
281
*/
282
- variant : PropTypes . oneOf ( [ 'filled' , 'outlined' , 'standard' ] ) ,
282
+ variant : PropTypes /* @typescript -to-proptypes-ignore */ . oneOf ( [
283
+ 'filled' ,
284
+ 'outlined' ,
285
+ 'standard' ,
286
+ ] ) ,
283
287
} ;
284
288
285
289
Select . muiName = 'Select' ;
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