File tree Expand file tree Collapse file tree 5 files changed +27
-0
lines changed Expand file tree Collapse file tree 5 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const Menu = (props) => {
11
11
children,
12
12
defaultSelected,
13
13
divider,
14
+ highlighted,
14
15
menuRef,
15
16
multiple,
16
17
onChange = ( ) => { } ,
@@ -27,6 +28,7 @@ const Menu = (props) => {
27
28
{ ...otherProps }
28
29
defaultSelected = { defaultSelected }
29
30
hasFocus = { hasFocus }
31
+ highlighted = { highlighted }
30
32
menuRef = { menuRef }
31
33
multiple = { multiple }
32
34
onBlur = { handleBlur }
@@ -102,6 +104,11 @@ Menu.propTypes = {
102
104
* Shows a divider at the bottom of the menu
103
105
*/
104
106
divider : PropTypes . bool ,
107
+ /**
108
+ * Semi-controlled way of having Options highlighted
109
+ * Takes the index of the option you want highlighted
110
+ */
111
+ highlighted : PropTypes . number ,
105
112
/**
106
113
* A callback ref that gets passed to the HTML
107
114
* element with `role="listbox"`
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const MenuGroup = (props) => {
8
8
const {
9
9
children,
10
10
defaultSelected,
11
+ highlighted,
11
12
menuRef,
12
13
multiple,
13
14
onChange,
@@ -21,6 +22,7 @@ const MenuGroup = (props) => {
21
22
< MenuBehavior
22
23
{ ...otherProps }
23
24
defaultSelected = { defaultSelected }
25
+ highlighted = { highlighted }
24
26
menuRef = { menuRef }
25
27
multiple = { multiple }
26
28
onChange = { onChange }
@@ -84,6 +86,13 @@ MenuGroup.propTypes = {
84
86
*/
85
87
// eslint-disable-next-line react/forbid-prop-types
86
88
defaultSelected : PropTypes . arrayOf ( PropTypes . any ) ,
89
+ /**
90
+ * Semi-controlled way of having Options highlighted
91
+ * Takes the index of the option you want highlighted
92
+ * This will take precedent over the Menu prop of the
93
+ * same name
94
+ */
95
+ highlighted : PropTypes . number ,
87
96
/**
88
97
* A callback ref that gets passed to the HTML
89
98
* element with `role="listbox"`
Original file line number Diff line number Diff line change @@ -275,6 +275,12 @@ const MenuBehavior = (props) => {
275
275
}
276
276
} , [ props . selected ] ) ;
277
277
278
+ useEffect ( ( ) => {
279
+ if ( props . highlighted >= 0 ) {
280
+ setHighlightIndexHook ( props . highlighted + 1 ) ;
281
+ }
282
+ } , [ props . highlighted ] ) ;
283
+
278
284
return props . children ( {
279
285
getActiveOption : getActiveOptionMethod ,
280
286
getHighlightIndex : getHighlightIndexMethod ,
@@ -306,6 +312,7 @@ MenuBehavior.propTypes = {
306
312
handleFocus : PropTypes . func ,
307
313
handleKeyDown : PropTypes . func ,
308
314
handleMouseMove : PropTypes . func ,
315
+ highlighted : PropTypes . func ,
309
316
menuRef : PropTypes . func ,
310
317
multiple : PropTypes . bool ,
311
318
onBlur : PropTypes . func ,
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ const MenuGroupPresenter = (props) => {
18
18
getHighlightIndex,
19
19
getOptionsInfo,
20
20
getPreviousEvent,
21
+ highlighted,
21
22
multiple,
22
23
onBlur : handleBlur ,
23
24
onFocus : handleFocus ,
@@ -44,6 +45,7 @@ const MenuGroupPresenter = (props) => {
44
45
handleFocus,
45
46
handleKeyDown,
46
47
handleMouseMove,
48
+ highlighted,
47
49
multiple,
48
50
selected,
49
51
setActiveOption,
@@ -180,6 +182,7 @@ MenuGroupPresenter.propTypes = {
180
182
getHighlightIndex : PropTypes . func ,
181
183
getOptionsInfo : PropTypes . func ,
182
184
getPreviousEvent : PropTypes . func ,
185
+ highlighted : PropTypes . number ,
183
186
menuRef : PropTypes . func ,
184
187
multiple : PropTypes . bool ,
185
188
onBlur : PropTypes . func ,
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ const MenuPresenter = (props) => {
71
71
delete payload . handleFocus ;
72
72
delete payload . handleKeyDown ;
73
73
delete payload . handleMouseMove ;
74
+ delete payload . highlighted ;
74
75
delete payload . setActiveOption ;
75
76
delete payload . setHighlightIndex ;
76
77
delete payload . setOptionsInfo ;
You can’t perform that action at this time.
0 commit comments