Skip to content

Commit beebb67

Browse files
authored
Merge pull request #21656 from akinwale/task-20690
fix: refocus the input field on the login screen after returning to the tab
2 parents 83a3a72 + 6d08325 commit beebb67

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/components/TextInput/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import styles from '../../styles/styles';
44
import * as styleConst from './styleConst';
55
import BaseTextInput from './BaseTextInput';
66
import * as baseTextInputPropTypes from './baseTextInputPropTypes';
7+
import DomUtils from '../../libs/DomUtils';
8+
import Visibility from '../../libs/Visibility';
79

810
class TextInput extends React.Component {
911
componentDidMount() {
@@ -14,6 +16,22 @@ class TextInput extends React.Component {
1416
if (this.props.name) {
1517
this.textInput.setAttribute('name', this.props.name);
1618
}
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();
1735
}
1836

1937
render() {

src/libs/DomUtils/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ function blurActiveElement() {
22
document.activeElement.blur();
33
}
44

5+
function getActiveElement() {
6+
return document.activeElement;
7+
}
8+
59
export default {
610
blurActiveElement,
11+
getActiveElement,
712
};

src/libs/DomUtils/index.native.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
function blurActiveElement() {}
22

3+
function getActiveElement() {
4+
return undefined;
5+
}
6+
37
export default {
48
blurActiveElement,
9+
getActiveElement,
510
};

0 commit comments

Comments
 (0)