@@ -18,6 +18,7 @@ type Props = React.HTMLAttributes<HTMLDivElement> & {
1818 textareaId ?: string ;
1919 textareaClassName ?: string ;
2020 autoFocus ?: boolean ;
21+ focusOnWindowFocus ?: boolean ;
2122 disabled ?: boolean ;
2223 form ?: string ;
2324 maxLength ?: number ;
@@ -87,6 +88,15 @@ export class EditorComponent extends React.Component<Props, State> {
8788
8889 componentDidMount ( ) {
8990 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+ }
90100 }
91101
92102 private _recordCurrentState = ( ) => {
@@ -161,6 +171,13 @@ export class EditorComponent extends React.Component<Props, State> {
161171 this . _history . offset ++ ;
162172 } ;
163173
174+ private _focusInput = ( ) => {
175+ const input = this . _input ;
176+
177+ if ( ! input ) return ;
178+ input . focus ( ) ;
179+ } ;
180+
164181 private _updateInput = ( record : Record ) => {
165182 const input = this . _input ;
166183
@@ -466,7 +483,7 @@ export class EditorComponent extends React.Component<Props, State> {
466483 selectionStart,
467484 selectionEnd,
468485 } ,
469- true ,
486+ true
470487 ) ;
471488
472489 this . props . onValueChange ( value ) ;
@@ -516,6 +533,7 @@ export class EditorComponent extends React.Component<Props, State> {
516533 insertSpaces,
517534 ignoreTabKey,
518535 preClassName,
536+ focusOnWindowFocus,
519537 ...rest
520538 } = this . props ;
521539
0 commit comments