Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pressing new chat shortcut twice remove the focus from search input #29202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/libs/DomUtils/index.native.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {BlurActiveElement, GetActiveElement} from './types';

const blurActiveElement: BlurActiveElement = () => {};
import GetActiveElement from './types';

const getActiveElement: GetActiveElement = () => null;

export default {
blurActiveElement,
getActiveElement,
};
13 changes: 1 addition & 12 deletions src/libs/DomUtils/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import {BlurActiveElement, GetActiveElement} from './types';

const blurActiveElement: BlurActiveElement = () => {
const activeElement = document.activeElement as HTMLElement;

if (!activeElement?.blur) {
return;
}

activeElement.blur();
};
import GetActiveElement from './types';

const getActiveElement: GetActiveElement = () => document.activeElement;

export default {
blurActiveElement,
getActiveElement,
};
3 changes: 1 addition & 2 deletions src/libs/DomUtils/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
type BlurActiveElement = () => void;
type GetActiveElement = () => Element | null;

export type {BlurActiveElement, GetActiveElement};
export default GetActiveElement;
14 changes: 2 additions & 12 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,7 @@ class AuthScreens extends React.Component {
this.unsubscribeSearchShortcut = KeyboardShortcut.subscribe(
searchShortcutConfig.shortcutKey,
() => {
Modal.close(() => {
if (Navigation.isActiveRoute(ROUTES.SEARCH)) {
return;
}
return Navigation.navigate(ROUTES.SEARCH);
});
Modal.close(() => Navigation.navigate(ROUTES.SEARCH));
},
searchShortcutConfig.descriptionKey,
searchShortcutConfig.modifiers,
Expand All @@ -199,12 +194,7 @@ class AuthScreens extends React.Component {
this.unsubscribeChatShortcut = KeyboardShortcut.subscribe(
chatShortcutConfig.shortcutKey,
() => {
Modal.close(() => {
if (Navigation.isActiveRoute(ROUTES.NEW)) {
return;
}
Navigation.navigate(ROUTES.NEW);
});
Modal.close(() => Navigation.navigate(ROUTES.NEW));
},
chatShortcutConfig.descriptionKey,
chatShortcutConfig.modifiers,
Expand Down
6 changes: 0 additions & 6 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import lodashGet from 'lodash/get';
import {CommonActions, getPathFromState, StackActions} from '@react-navigation/native';
import {getActionFromState} from '@react-navigation/core';
import Log from '../Log';
import DomUtils from '../DomUtils';
import linkTo from './linkTo';
import ROUTES from '../../ROUTES';
import linkingConfig from './linkingConfig';
Expand Down Expand Up @@ -92,11 +91,6 @@ function navigate(route = ROUTES.HOME, type) {
return;
}

// A pressed navigation button will remain focused, keeping its tooltip visible, even if it's supposed to be out of view.
// To prevent that we blur the button manually (especially for Safari, where the mouse leave event is missing).
// More info: https://github.com/Expensify/App/issues/13146
DomUtils.blurActiveElement();

linkTo(navigationRef.current, route, type);
}

Expand Down
Loading