Skip to content

Commit

Permalink
Merge pull request Expensify#31899 from dukenv0307/fix/30867
Browse files Browse the repository at this point in the history
Consistent key press focus logic between composer and emoji picker
  • Loading branch information
marcaaron authored Dec 5, 2023
2 parents 2c1ee2a + 3d4bd06 commit e4586d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/components/EmojiPicker/EmojiPickerMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import compose from '@libs/compose';
import * as EmojiUtils from '@libs/EmojiUtils';
import isEnterWhileComposition from '@libs/KeyboardShortcut/isEnterWhileComposition';
import * as ReportUtils from '@libs/ReportUtils';
import * as StyleUtils from '@styles/StyleUtils';
import useThemeStyles from '@styles/useThemeStyles';
import * as User from '@userActions/User';
Expand Down Expand Up @@ -313,7 +314,7 @@ function EmojiPickerMenu(props) {
// Enable keyboard movement if tab or enter is pressed or if shift is pressed while the input
// is not focused, so that the navigation and tab cycling can be done using the keyboard without
// interfering with the input behaviour.
if (keyBoardEvent.key === 'Tab' || keyBoardEvent.key === 'Enter' || (keyBoardEvent.key === 'Shift' && searchInputRef.current && !searchInputRef.current.isFocused())) {
if (!ReportUtils.shouldAutoFocusOnKeyPress(keyBoardEvent)) {
setIsUsingKeyboardMovement(true);
return;
}
Expand Down
19 changes: 19 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import lodashEscape from 'lodash/escape';
import lodashFindLastIndex from 'lodash/findLastIndex';
import lodashIntersection from 'lodash/intersection';
import lodashIsEqual from 'lodash/isEqual';
import React from 'react';
import Onyx, {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import {SvgProps} from 'react-native-svg';
import {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -4251,6 +4252,23 @@ function shouldDisableWelcomeMessage(report: OnyxEntry<Report>, policy: OnyxEntr
return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy);
}

function shouldAutoFocusOnKeyPress(event: KeyboardEvent): boolean {
if (event.key.length > 1) {
return false;
}

// If a key is pressed in combination with Meta, Control or Alt do not focus
if (event.ctrlKey || event.metaKey) {
return false;
}

if (event.code === 'Space') {
return false;
}

return true;
}

/**
* Navigates to the appropriate screen based on the presence of a private note for the current user.
*/
Expand Down Expand Up @@ -4433,6 +4451,7 @@ export {
shouldDisableWelcomeMessage,
navigateToPrivateNotes,
canEditWriteCapability,
shouldAutoFocusOnKeyPress,
};

export type {OptionData};
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,7 @@ function ComposerWithSuggestions({
return;
}

// If the key pressed is non-character keys like Enter, Shift, ... do not focus
if (e.key.length > 1) {
return;
}

// If a key is pressed in combination with Meta, Control or Alt do not focus
if (e.metaKey || e.ctrlKey || e.altKey) {
return;
}

// If the space key is pressed, do not focus
if (e.code === 'Space') {
if (!ReportUtils.shouldAutoFocusOnKeyPress(e)) {
return;
}

Expand Down

0 comments on commit e4586d0

Please sign in to comment.