Skip to content

Commit

Permalink
Merge pull request #21656 from akinwale/task-20690
Browse files Browse the repository at this point in the history
fix: refocus the input field on the login screen after returning to the tab
  • Loading branch information
youssef-lr authored Jul 25, 2023
2 parents 83a3a72 + 6d08325 commit beebb67
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/TextInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import styles from '../../styles/styles';
import * as styleConst from './styleConst';
import BaseTextInput from './BaseTextInput';
import * as baseTextInputPropTypes from './baseTextInputPropTypes';
import DomUtils from '../../libs/DomUtils';
import Visibility from '../../libs/Visibility';

class TextInput extends React.Component {
componentDidMount() {
Expand All @@ -14,6 +16,22 @@ class TextInput extends React.Component {
if (this.props.name) {
this.textInput.setAttribute('name', this.props.name);
}

// Forcefully activate the soft keyboard when the user switches between tabs while input was focused.
this.removeVisibilityListener = Visibility.onVisibilityChange(() => {
if (!Visibility.isVisible() || !this.textInput || DomUtils.getActiveElement() !== this.textInput) {
return;
}
this.textInput.blur();
this.textInput.focus();
});
}

componentWillUnmount() {
if (!this.removeVisibilityListener) {
return;
}
this.removeVisibilityListener();
}

render() {
Expand Down
5 changes: 5 additions & 0 deletions src/libs/DomUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ function blurActiveElement() {
document.activeElement.blur();
}

function getActiveElement() {
return document.activeElement;
}

export default {
blurActiveElement,
getActiveElement,
};
5 changes: 5 additions & 0 deletions src/libs/DomUtils/index.native.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function blurActiveElement() {}

function getActiveElement() {
return undefined;
}

export default {
blurActiveElement,
getActiveElement,
};

0 comments on commit beebb67

Please sign in to comment.