Skip to content

Commit dff7409

Browse files
committed
add/remove focus listeners from editor when prop changes
1 parent 9c63b79 commit dff7409

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/features/common/components/code-editor/editor.component.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,18 @@ export class EditorComponent extends React.Component<Props, State> {
9393
}
9494
}
9595

96-
componentWillUnmount() {
97-
if (this.props.focusOnWindowFocus) {
98-
window.removeEventListener("focus", this._focusInput);
96+
componentDidUpdate(prevProps: Readonly<Props>): void {
97+
if (prevProps.focusOnWindowFocus !== this.props.focusOnWindowFocus) {
98+
this.props.focusOnWindowFocus
99+
? window.addEventListener("focus", this._focusInput)
100+
: window.removeEventListener("focus", this._focusInput);
99101
}
100102
}
101103

104+
componentWillUnmount() {
105+
window.removeEventListener("focus", this._focusInput);
106+
}
107+
102108
private _recordCurrentState = () => {
103109
const input = this._input;
104110

0 commit comments

Comments
 (0)