Skip to content

Commit 8df7c9e

Browse files
Merge pull request #151 from MercuryTechnologies/fixOnSelectionBug
Fix onSelection bug
2 parents f4e0de8 + b696dc2 commit 8df7c9e

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

src/Wrapper.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,27 @@ const checkedProps = {
1515
tag: PropTypes.string
1616
};
1717

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+
1828
class AriaMenuButtonWrapper extends React.Component {
1929
static propTypes = checkedProps;
2030
static defaultProps = { tag: 'div' };
2131

2232
constructor(props) {
2333
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))
3139
}
3240

3341
render() {

src/createManager.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,7 @@ const focusGroupOptions = {
88

99
const protoManager = {
1010
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);
2412

2513
this.handleBlur = handleBlur.bind(this);
2614
this.handleSelection = handleSelection.bind(this);
@@ -42,6 +30,29 @@ const protoManager = {
4230
this.isOpen = false;
4331
},
4432

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+
4556
focusItem(index) {
4657
this.focusGroup.focusNodeAtIndex(index);
4758
},

0 commit comments

Comments
 (0)