@@ -18,6 +18,7 @@ type Props = React.HTMLAttributes<HTMLDivElement> & {
18
18
textareaId ?: string ;
19
19
textareaClassName ?: string ;
20
20
autoFocus ?: boolean ;
21
+ focusOnWindowFocus ?: boolean ;
21
22
disabled ?: boolean ;
22
23
form ?: string ;
23
24
maxLength ?: number ;
@@ -87,6 +88,15 @@ export class EditorComponent extends React.Component<Props, State> {
87
88
88
89
componentDidMount ( ) {
89
90
this . _recordCurrentState ( ) ;
91
+ if ( this . props . focusOnWindowFocus ) {
92
+ window . addEventListener ( "focus" , this . _focusInput ) ;
93
+ }
94
+ }
95
+
96
+ componentWillUnmount ( ) {
97
+ if ( this . props . focusOnWindowFocus ) {
98
+ window . removeEventListener ( "focus" , this . _focusInput ) ;
99
+ }
90
100
}
91
101
92
102
private _recordCurrentState = ( ) => {
@@ -161,6 +171,13 @@ export class EditorComponent extends React.Component<Props, State> {
161
171
this . _history . offset ++ ;
162
172
} ;
163
173
174
+ private _focusInput = ( ) => {
175
+ const input = this . _input ;
176
+
177
+ if ( ! input ) return ;
178
+ input . focus ( ) ;
179
+ } ;
180
+
164
181
private _updateInput = ( record : Record ) => {
165
182
const input = this . _input ;
166
183
@@ -466,7 +483,7 @@ export class EditorComponent extends React.Component<Props, State> {
466
483
selectionStart,
467
484
selectionEnd,
468
485
} ,
469
- true ,
486
+ true
470
487
) ;
471
488
472
489
this . props . onValueChange ( value ) ;
@@ -516,6 +533,7 @@ export class EditorComponent extends React.Component<Props, State> {
516
533
insertSpaces,
517
534
ignoreTabKey,
518
535
preClassName,
536
+ focusOnWindowFocus,
519
537
...rest
520
538
} = this . props ;
521
539
0 commit comments