File tree Expand file tree Collapse file tree 2 files changed +39
-20
lines changed Expand file tree Collapse file tree 2 files changed +39
-20
lines changed Original file line number Diff line number Diff line change @@ -15,19 +15,27 @@ const checkedProps = {
15
15
tag : PropTypes . string
16
16
} ;
17
17
18
+ const managerOptionsFromProps = ( props ) => {
19
+ return {
20
+ onMenuToggle : props . onMenuToggle ,
21
+ onSelection : props . onSelection ,
22
+ closeOnSelection : props . closeOnSelection ,
23
+ closeOnBlur : props . closeOnBlur ,
24
+ id : props . id
25
+ }
26
+ }
27
+
18
28
class AriaMenuButtonWrapper extends React . Component {
19
29
static propTypes = checkedProps ;
20
30
static defaultProps = { tag : 'div' } ;
21
31
22
32
constructor ( props ) {
23
33
super ( props ) ;
24
- this . manager = createManager ( {
25
- onMenuToggle : this . props . onMenuToggle ,
26
- onSelection : this . props . onSelection ,
27
- closeOnSelection : this . props . closeOnSelection ,
28
- closeOnBlur : this . props . closeOnBlur ,
29
- id : this . props . id
30
- } ) ;
34
+ this . manager = createManager ( managerOptionsFromProps ( props ) ) ;
35
+ }
36
+
37
+ componentDidUpdate ( ) {
38
+ this . manager . updateOptions ( managerOptionsFromProps ( this . props ) )
31
39
}
32
40
33
41
render ( ) {
Original file line number Diff line number Diff line change @@ -8,19 +8,7 @@ const focusGroupOptions = {
8
8
9
9
const protoManager = {
10
10
init ( options ) {
11
- this . options = options || { } ;
12
-
13
- if ( typeof this . options . closeOnSelection === 'undefined' ) {
14
- this . options . closeOnSelection = true ;
15
- }
16
-
17
- if ( typeof this . options . closeOnBlur === 'undefined' ) {
18
- this . options . closeOnBlur = true ;
19
- }
20
-
21
- if ( this . options . id ) {
22
- externalStateControl . registerManager ( this . options . id , this ) ;
23
- }
11
+ this . updateOptions ( options ) ;
24
12
25
13
this . handleBlur = handleBlur . bind ( this ) ;
26
14
this . handleSelection = handleSelection . bind ( this ) ;
@@ -42,6 +30,29 @@ const protoManager = {
42
30
this . isOpen = false ;
43
31
} ,
44
32
33
+ updateOptions ( options ) {
34
+ const oldOptions = this . options ;
35
+
36
+ this . options = options || this . options || { } ;
37
+
38
+ if ( typeof this . options . closeOnSelection === 'undefined' ) {
39
+ this . options . closeOnSelection = true ;
40
+ }
41
+
42
+ if ( typeof this . options . closeOnBlur === 'undefined' ) {
43
+ this . options . closeOnBlur = true ;
44
+ }
45
+
46
+ if ( this . options . id ) {
47
+ externalStateControl . registerManager ( this . options . id , this ) ;
48
+ }
49
+
50
+ if ( oldOptions && oldOptions . id && oldOptions . id !== this . options . id ) {
51
+ externalStateControl . unregisterManager ( this . options . id , this ) ;
52
+ }
53
+
54
+ } ,
55
+
45
56
focusItem ( index ) {
46
57
this . focusGroup . focusNodeAtIndex ( index ) ;
47
58
} ,
You can’t perform that action at this time.
0 commit comments