Commit 39063ab 1 parent b9ddd6b commit 39063ab Copy full SHA for 39063ab
File tree 2 files changed +34
-8
lines changed
docs/src/pages/components/autocomplete
2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -5,16 +5,29 @@ import TextField from '@material-ui/core/TextField';
5
5
import Autocomplete from '@material-ui/lab/Autocomplete' ;
6
6
7
7
export default function FixedTags ( ) {
8
+ const fixedOptions = [ top100Films [ 6 ] ] ;
9
+ const [ value , setValue ] = React . useState ( [ ...fixedOptions , top100Films [ 13 ] ] ) ;
10
+
8
11
return (
9
12
< Autocomplete
10
13
multiple
11
14
id = "fixed-tags-demo"
15
+ value = { value }
16
+ onChange = { ( event , newValue ) => {
17
+ setValue ( [
18
+ ...fixedOptions ,
19
+ ...newValue . filter ( ( option ) => fixedOptions . indexOf ( option ) === - 1 ) ,
20
+ ] ) ;
21
+ } }
12
22
options = { top100Films }
13
23
getOptionLabel = { ( option ) => option . title }
14
- defaultValue = { [ top100Films [ 6 ] , top100Films [ 13 ] ] }
15
- renderTags = { ( value , getTagProps ) =>
16
- value . map ( ( option , index ) => (
17
- < Chip label = { option . title } { ...getTagProps ( { index } ) } disabled = { index === 0 } />
24
+ renderTags = { ( tagValue , getTagProps ) =>
25
+ tagValue . map ( ( option , index ) => (
26
+ < Chip
27
+ label = { option . title }
28
+ { ...getTagProps ( { index } ) }
29
+ disabled = { fixedOptions . indexOf ( option ) !== - 1 }
30
+ />
18
31
) )
19
32
}
20
33
style = { { width : 500 } }
Original file line number Diff line number Diff line change @@ -5,16 +5,29 @@ import TextField from '@material-ui/core/TextField';
5
5
import Autocomplete from '@material-ui/lab/Autocomplete' ;
6
6
7
7
export default function FixedTags ( ) {
8
+ const fixedOptions = [ top100Films [ 6 ] ] ;
9
+ const [ value , setValue ] = React . useState ( [ ...fixedOptions , top100Films [ 13 ] ] ) ;
10
+
8
11
return (
9
12
< Autocomplete
10
13
multiple
11
14
id = "fixed-tags-demo"
15
+ value = { value }
16
+ onChange = { ( event , newValue ) => {
17
+ setValue ( [
18
+ ...fixedOptions ,
19
+ ...newValue . filter ( ( option ) => fixedOptions . indexOf ( option ) === - 1 ) ,
20
+ ] ) ;
21
+ } }
12
22
options = { top100Films }
13
23
getOptionLabel = { ( option ) => option . title }
14
- defaultValue = { [ top100Films [ 6 ] , top100Films [ 13 ] ] }
15
- renderTags = { ( value , getTagProps ) =>
16
- value . map ( ( option , index ) => (
17
- < Chip label = { option . title } { ...getTagProps ( { index } ) } disabled = { index === 0 } />
24
+ renderTags = { ( tagValue , getTagProps ) =>
25
+ tagValue . map ( ( option , index ) => (
26
+ < Chip
27
+ label = { option . title }
28
+ { ...getTagProps ( { index } ) }
29
+ disabled = { fixedOptions . indexOf ( option ) !== - 1 }
30
+ />
18
31
) )
19
32
}
20
33
style = { { width : 500 } }
You can’t perform that action at this time.
0 commit comments