Skip to content

Commit

Permalink
Merge pull request #20667 from hoangzinh/df/20092
Browse files Browse the repository at this point in the history
Fix welcome message input is not auto focus after going back
  • Loading branch information
AndrewGable authored Jun 14, 2023
2 parents 81e6cc2 + b940154 commit 14e3e1b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/pages/workspace/WorkspaceInviteMessagePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ROUTES from '../../ROUTES';
import * as Localize from '../../libs/Localize';
import Form from '../../components/Form';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import withNavigationFocus from '../../components/withNavigationFocus';
import PressableWithoutFeedback from '../../components/Pressable/PressableWithoutFeedback';

const personalDetailsPropTypes = PropTypes.shape({
Expand Down Expand Up @@ -80,17 +81,14 @@ class WorkspaceInviteMessagePage extends React.Component {
}

componentDidMount() {
this.focusTimeout = setTimeout(() => {
this.welcomeMessageInputRef.focus();
// Below condition is needed for web, desktop and mweb only, for native cursor is set at end by default.
if (this.welcomeMessageInputRef.value && this.welcomeMessageInputRef.setSelectionRange) {
const length = this.welcomeMessageInputRef.value.length;
this.welcomeMessageInputRef.setSelectionRange(length, length);
}
}, CONST.ANIMATED_TRANSITION);
this.focusWelcomeMessageInput();
}

componentDidUpdate(prevProps) {
if (!prevProps.isFocused && this.props.isFocused) {
this.focusWelcomeMessageInput();
}

if (
!(
(prevProps.preferredLocale !== this.props.preferredLocale || prevProps.policy.name !== this.props.policy.name) &&
Expand Down Expand Up @@ -130,6 +128,17 @@ class WorkspaceInviteMessagePage extends React.Component {
Link.openExternalLink(CONST.PRIVACY_URL);
}

focusWelcomeMessageInput() {
this.focusTimeout = setTimeout(() => {
this.welcomeMessageInputRef.focus();
// Below condition is needed for web, desktop and mweb only, for native cursor is set at end by default.
if (this.welcomeMessageInputRef.value && this.welcomeMessageInputRef.setSelectionRange) {
const length = this.welcomeMessageInputRef.value.length;
this.welcomeMessageInputRef.setSelectionRange(length, length);
}
}, CONST.ANIMATED_TRANSITION);
}

validate() {
const errorFields = {};
if (_.isEmpty(this.props.invitedMembersDraft)) {
Expand Down Expand Up @@ -227,4 +236,5 @@ export default compose(
key: ({route}) => `${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`,
},
}),
withNavigationFocus,
)(WorkspaceInviteMessagePage);

0 comments on commit 14e3e1b

Please sign in to comment.