diff --git a/package.json b/package.json index c1a22c9..b8058a1 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "chai": "^4.1.0", "chai-enzyme": "^1.0.0-beta.0", "enzyme": "^3.3.0", - "enzyme-adapter-react-16": "^1.1.1", + "enzyme-adapter-react-16": "^1.7.1", "eslint": "^4.2.0", "eslint-config-airbnb": "15.1.0", "eslint-plugin-import": "^2.7.0", diff --git a/src/Lock.js b/src/Lock.js index 957bb24..af36e49 100644 --- a/src/Lock.js +++ b/src/Lock.js @@ -31,9 +31,11 @@ class FocusLock extends Component { if (this.state.observed && this.props.onActivation) { this.props.onActivation(this.state.observed); } + this.isActive = true; }; onDeactivation = () => { + this.isActive = false; if ( this.props.returnFocus && this.originalFocusedElement && @@ -47,11 +49,22 @@ class FocusLock extends Component { } }; + onFocus = (event) => { + if (this.isActive) { + onFocus(event); + } + }; + + onBlur = onBlur; + setObserveNode = observed => this.setState({ observed, }); + // active status is tracked outside React state + isActive = false; + update = () => this.setState(prevState => ({ escapeAttempts: prevState.escapeAttempts + 1, @@ -98,8 +111,8 @@ class FocusLock extends Component { ref={this.setObserveNode} {...lockProps} className={className} - onBlur={onBlur} - onFocus={onFocus} + onBlur={this.onBlur} + onFocus={this.onFocus} >