@@ -23,7 +23,6 @@ const propTypes = {
23
23
* If true, renders checkmark icon on the selected Menu Item.
24
24
*/
25
25
checkmark : React . PropTypes . bool ,
26
- disabled : React . PropTypes . bool ,
27
26
label : React . PropTypes . string ,
28
27
/**
29
28
* Custom element that overrides the default Menu Item component.
@@ -32,25 +31,14 @@ const propTypes = {
32
31
/**
33
32
* If true, component renders specifically to work inside Modal.
34
33
*/
35
- modal : React . PropTypes . bool ,
36
34
onClick : React . PropTypes . func ,
37
35
onSelect : React . PropTypes . func ,
38
36
/**
39
37
* Menu item data.
40
38
*/
41
39
options : React . PropTypes . array . isRequired ,
42
- placeholder : React . PropTypes . string ,
43
- required : React . PropTypes . bool ,
44
- /**
45
- * Current selected item.
46
- */
47
- value : React . PropTypes . node ,
48
40
} ;
49
41
const defaultProps = {
50
- disabled : false ,
51
- modal : true ,
52
- required : false ,
53
- placeholder : "Select an Option" ,
54
42
checkmark : true
55
43
} ;
56
44
@@ -65,11 +53,12 @@ class SLDSMenuPicklist extends React.Component {
65
53
isOpen : false ,
66
54
lastBlurredIndex : - 1 ,
67
55
lastBlurredTimeStamp : - 1 ,
68
- selectedIndex : this . getIndexByValue ( this . props . value ) ,
56
+ selectedIndex : this . props . selectedIndex ,
69
57
/* triggerId is the id of the element that triggers the Menu to open.
70
58
* Need this for aria-labelledby on <ul> in Menu for accessibility. */
71
59
triggerId : this . props . label ? this . props . label . replace ( / \s + / g, '' ) + '_Button' : 'Picklist_Button' ,
72
60
} ;
61
+
73
62
}
74
63
75
64
componentWillUnmount ( ) {
@@ -86,45 +75,22 @@ class SLDSMenuPicklist extends React.Component {
86
75
this . handleClose ( ) ;
87
76
}
88
77
89
- if ( this . props . value !== prevProps . value ||
78
+ if ( this . props . selectedIndex !== prevProps . selectedIndex ||
90
79
! isEqual ( this . props . options , prevProps . options ) ) {
91
- var newSelectedIndex = this . getIndexByValue ( this . props . value ) ;
92
- if ( newSelectedIndex !== this . state . selectedIndex ) {
93
- this . handleSelect ( newSelectedIndex ) ;
80
+ if ( this . props . selectedIndex !== this . state . selectedIndex ) {
81
+ this . handleSelect ( this . props . selectedIndex ) ;
94
82
}
95
83
}
96
84
}
97
85
98
- getIndexByValue ( value ) {
99
- let foundIndex = - 1 ;
100
- if ( this . props . options && this . props . options . length ) {
101
- this . props . options . some ( ( element , index , array ) => {
102
- if ( element && element . value === value ) {
103
- foundIndex = index ;
104
- return true ;
105
- }
106
- return false ;
107
- } ) ;
108
- }
109
- return foundIndex ;
110
- }
111
-
112
- getValueByIndex ( index ) {
113
- const option = this . props . options [ index ] ;
114
- if ( option ) {
115
- return this . props . options [ index ] ;
116
- }
117
- }
118
-
119
86
handleSelect ( index ) {
120
87
this . setState ( { selectedIndex : index } )
121
88
if ( this . props . onSelect ) {
122
- this . props . onSelect ( this . getValueByIndex ( index ) ) ;
89
+ this . props . onSelect ( index ) ;
123
90
}
124
91
}
125
92
126
93
handleClose ( ) {
127
- console . log ( '!!! handleClose !!!' ) ;
128
94
if ( this . props . onCancel ) {
129
95
this . props . onCancel ( ) ;
130
96
}
0 commit comments