File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import styles from '../../styles/styles';
4
4
import * as styleConst from './styleConst' ;
5
5
import BaseTextInput from './BaseTextInput' ;
6
6
import * as baseTextInputPropTypes from './baseTextInputPropTypes' ;
7
+ import DomUtils from '../../libs/DomUtils' ;
8
+ import Visibility from '../../libs/Visibility' ;
7
9
8
10
class TextInput extends React . Component {
9
11
componentDidMount ( ) {
@@ -14,6 +16,22 @@ class TextInput extends React.Component {
14
16
if ( this . props . name ) {
15
17
this . textInput . setAttribute ( 'name' , this . props . name ) ;
16
18
}
19
+
20
+ // Forcefully activate the soft keyboard when the user switches between tabs while input was focused.
21
+ this . removeVisibilityListener = Visibility . onVisibilityChange ( ( ) => {
22
+ if ( ! Visibility . isVisible ( ) || ! this . textInput || DomUtils . getActiveElement ( ) !== this . textInput ) {
23
+ return ;
24
+ }
25
+ this . textInput . blur ( ) ;
26
+ this . textInput . focus ( ) ;
27
+ } ) ;
28
+ }
29
+
30
+ componentWillUnmount ( ) {
31
+ if ( ! this . removeVisibilityListener ) {
32
+ return ;
33
+ }
34
+ this . removeVisibilityListener ( ) ;
17
35
}
18
36
19
37
render ( ) {
Original file line number Diff line number Diff line change @@ -2,6 +2,11 @@ function blurActiveElement() {
2
2
document . activeElement . blur ( ) ;
3
3
}
4
4
5
+ function getActiveElement ( ) {
6
+ return document . activeElement ;
7
+ }
8
+
5
9
export default {
6
10
blurActiveElement,
11
+ getActiveElement,
7
12
} ;
Original file line number Diff line number Diff line change 1
1
function blurActiveElement ( ) { }
2
2
3
+ function getActiveElement ( ) {
4
+ return undefined ;
5
+ }
6
+
3
7
export default {
4
8
blurActiveElement,
9
+ getActiveElement,
5
10
} ;
You can’t perform that action at this time.
0 commit comments