Skip to content
Merged
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
18 changes: 8 additions & 10 deletions src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r
setFilteredEmojis(allEmojis);
setHeaderIndices(headerRowIndices);
setFocusedIndex(-1);
setHighlightFirstEmoji(false);
setHighlightEmoji(false);
return;
}
Expand All @@ -139,14 +140,6 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r
return;
}

if (!isEnterWhileComposition(keyBoardEvent) && keyBoardEvent.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey) {
// On web, avoid this Enter default input action; otherwise, it will add a new line in the subsequently focused composer.
keyBoardEvent.preventDefault();
// On mWeb, avoid propagating this Enter keystroke to Pressable child component; otherwise, it will trigger the onEmojiSelected callback again.
keyBoardEvent.stopPropagation();
return;
}
Comment on lines -142 to -148
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why you remove the whole condition, Shouldn't we keep the return early here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed it because it won't affect the code below it.

// 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 && !isTextInputFocused(searchInputRef))) {
setIsUsingKeyboardMovement(true);
}
// We allow typing in the search box if any key is pressed apart from Arrow keys.
if (searchInputRef.current && !isTextInputFocused(searchInputRef) && ReportUtils.shouldAutoFocusOnKeyPress(keyBoardEvent)) {
searchInputRef.current.focus();
}
},

For

// We allow typing in the search box if any key is pressed apart from Arrow keys.
if (searchInputRef.current && !isTextInputFocused(searchInputRef) && ReportUtils.shouldAutoFocusOnKeyPress(keyBoardEvent)) {
searchInputRef.current.focus();
}

it's only executed if shouldAutoFocusOnKeyPress is true which is false for ENTER.

App/src/libs/ReportUtils.ts

Lines 7595 to 7598 in c3d33fc

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

For

// 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 && !isTextInputFocused(searchInputRef))) {
setIsUsingKeyboardMovement(true);
}

the keyboard movement state is used to show the focused state of emoji item.

const isEmojiFocused = index === focusedIndex && isUsingKeyboardMovement;

The emoji will be focused when we use arrow key, tab, or hold down mouse on it. The time we press Enter, the emoji will be selected. From my understanding, the isUsingKeyboardMovement state is used to not show the blue outline on the emoji when focused using mouse.

But it will still show anyway with the mouse because when focused, we update the focused index.

onFocus={() => setFocusedIndex(index)}

which always update isUsingKeyboardMovement to true.

const onFocusedIndexChange = useCallback(
(newIndex: number) => {
if (filteredEmojis.length === 0) {
return;
}
if (highlightFirstEmoji) {
setHighlightFirstEmoji(false);
}
if (!isUsingKeyboardMovement) {
setIsUsingKeyboardMovement(true);
}

We can remove Enter from the if if you want.

if (keyBoardEvent.key === 'Tab' || keyBoardEvent.key === 'Enter' || (keyBoardEvent.key === 'Shift' && searchInputRef.current && !isTextInputFocused(searchInputRef))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can remove Enter from the if if you want.

To be honest, I don't understand what is the purpose of keyBoardEvent.key === 'Enter' ||, As I see in the code clicking Enter should do one of

  1. select the emoji and close the menu
  2. select the category

In the both cases this condition keyBoardEvent.key === 'Enter' || it is not reachable in the old code here, and beside your explanation about isUsingKeyboardMovement it seems to don't do any function but let's know what @aldo-expensify think before remove it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the both cases this condition keyBoardEvent.key === 'Enter' || it is not reachable in the old code here

Yeah, good point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the delay here, I'm just starting to look at this 👁️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm very unfamiliar with the details here, and I'm wanting to avoid spending to much time to understand all the details around it. I tested and it appears to be working well for me, so I'm going to just assume that we don't need to change anything here since it is working.


// 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.
Expand Down Expand Up @@ -182,9 +175,13 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r
if ('types' in item || 'name' in item) {
const emoji = typeof preferredSkinTone === 'number' && preferredSkinTone !== -1 && item?.types?.at(preferredSkinTone) ? item.types.at(preferredSkinTone) : item.code;
onEmojiSelected(emoji ?? '', item);
// On web, avoid this Enter default input action; otherwise, it will add a new line in the subsequently focused composer.
keyBoardEvent.preventDefault();
// On mWeb, avoid propagating this Enter keystroke to Pressable child component; otherwise, it will trigger the onEmojiSelected callback again.
keyBoardEvent.stopPropagation();
}
},
{shouldPreventDefault: true, shouldStopPropagation: true},
{shouldPreventDefault: false},
);

/**
Expand Down Expand Up @@ -239,8 +236,9 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r

const calculatedOffset = Math.floor(headerIndex / CONST.EMOJI_NUM_PER_ROW) * CONST.EMOJI_PICKER_HEADER_HEIGHT;
emojiListRef.current?.scrollToOffset({offset: calculatedOffset, animated: true});
setFocusedIndex(headerIndex);
},
[emojiListRef],
[emojiListRef, setFocusedIndex],
);

/**
Expand Down