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

Consistent key press focus logic between composer and emoji picker #31899

Merged
merged 9 commits into from
Dec 5, 2023
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
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)) {
Comment on lines -316 to +317
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change caused a regression in EmojiPickerMenu. When filtering the emoji list, it's focusing the emoji each time backspace is hit

Screen.Recording.2023-12-06.at.09.58.13.mov

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') {
dukenv0307 marked this conversation as resolved.
Show resolved Hide resolved
if (!ReportUtils.shouldAutoFocusOnKeyPress(e)) {
return;
}

Expand Down
Loading