Skip to content

Commit e1a99d0

Browse files
thepaperpilotvkbansal
authored andcommitted
Fixed clicking on items in a submenu not removing event listeners (#227)
1 parent 3e9c407 commit e1a99d0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/SubMenu.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default class SubMenu extends AbstractMenu {
108108

109109
if (this.closetimer) clearTimeout(this.closetimer);
110110

111-
this.unregisterHandlers();
111+
this.unregisterHandlers(true);
112112
}
113113

114114
getMenuPosition = () => {
@@ -212,9 +212,11 @@ export default class SubMenu extends AbstractMenu {
212212
document.addEventListener('keydown', this.handleKeyNavigation);
213213
}
214214

215-
unregisterHandlers = () => {
215+
unregisterHandlers = (dismounting) => {
216216
document.removeEventListener('keydown', this.handleKeyNavigation);
217-
document.addEventListener('keydown', this.props.parentKeyNavigationHandler);
217+
if (!dismounting) {
218+
document.addEventListener('keydown', this.props.parentKeyNavigationHandler);
219+
}
218220
}
219221

220222
render() {

0 commit comments

Comments
 (0)