@@ -4,11 +4,25 @@ import TextField, { TextFieldProps } from '@material-ui/core/TextField';
4
4
import { unstable_useId as useId } from '@material-ui/core/utils' ;
5
5
import { GridLoadIcon } from '../../icons/index' ;
6
6
import { GridFilterInputValueProps } from './GridFilterInputValueProps' ;
7
+ import { GridColDef } from '../../../models/colDef/gridColDef' ;
8
+
9
+ const renderSingleSelectOptions = ( { valueOptions } : GridColDef ) =>
10
+ [ '' , ...valueOptions ! ] . map ( ( option ) =>
11
+ typeof option === 'string' ? (
12
+ < option key = { option } value = { option } >
13
+ { option }
14
+ </ option >
15
+ ) : (
16
+ < option key = { option . value } value = { option . value } >
17
+ { option . label }
18
+ </ option >
19
+ ) ,
20
+ ) ;
7
21
8
22
export const SUBMIT_FILTER_STROKE_TIME = 500 ;
9
23
10
24
export interface GridTypeFilterInputValueProps extends GridFilterInputValueProps {
11
- type ?: 'text' | 'number' | 'date' | 'datetime-local' ;
25
+ type ?: 'text' | 'number' | 'date' | 'datetime-local' | 'singleSelect' ;
12
26
}
13
27
14
28
export function GridFilterInputValue ( props : GridTypeFilterInputValueProps & TextFieldProps ) {
@@ -17,6 +31,16 @@ export function GridFilterInputValue(props: GridTypeFilterInputValueProps & Text
17
31
const [ filterValueState , setFilterValueState ] = React . useState ( item . value || '' ) ;
18
32
const [ applying , setIsApplying ] = React . useState ( false ) ;
19
33
const id = useId ( ) ;
34
+ const singleSelectProps : TextFieldProps =
35
+ type === 'singleSelect'
36
+ ? {
37
+ select : true ,
38
+ SelectProps : {
39
+ native : true ,
40
+ } ,
41
+ children : renderSingleSelectOptions ( apiRef . current . getColumn ( item . columnField ) ) ,
42
+ }
43
+ : { } ;
20
44
21
45
const onFilterChange = React . useCallback (
22
46
( event ) => {
@@ -57,6 +81,7 @@ export function GridFilterInputValue(props: GridTypeFilterInputValueProps & Text
57
81
InputLabelProps = { {
58
82
shrink : true ,
59
83
} }
84
+ { ...singleSelectProps }
60
85
{ ...others }
61
86
/>
62
87
) ;
0 commit comments