Skip to content

Commit

Permalink
fix(OverflowMenu): cleanup timeout upon unmount (carbon-design-system…
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh authored and tw15egan committed May 1, 2019
1 parent 81f90a7 commit 4b0a5cb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/OverflowMenu/OverflowMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ class OverflowMenu extends Component {
*/
_hFocusIn = null;

/**
* The timeout handle for handling `blur` event.
* @private
*/
_hBlurTimeout;

shouldComponentUpdate(nextProps, nextState) {
if (nextState.open && !this.state.open) {
requestAnimationFrame(() => {
Expand Down Expand Up @@ -398,6 +404,10 @@ class OverflowMenu extends Component {
}

componentWillUnmount() {
if (typeof this._hBlurTimeout === 'number') {
clearTimeout(this._hBlurTimeout);
this._hBlurTimeout = undefined;
}
this.hResize.release();
}

Expand Down Expand Up @@ -460,7 +470,12 @@ class OverflowMenu extends Component {
}
evt.persist();
// event loop hack
setTimeout(() => {
if (typeof this._hBlurTimeout === 'number') {
clearTimeout(this._hBlurTimeout);
this._hBlurTimeout = undefined;
}
this._hBlurTimeout = setTimeout(() => {
this._hBlurTimeout = undefined;
if (!this.menuEl.contains(evt.target.ownerDocument.activeElement)) {
this.setState({ open: false });
}
Expand Down

0 comments on commit 4b0a5cb

Please sign in to comment.