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

[$250] Web/Desktop - Emoji Picker - Nothing happens when user press "Enter" on emoji category icon #50561

Open
2 of 6 tasks
lanitochka17 opened this issue Oct 10, 2024 · 21 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 10, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.47-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5072091
Email or phone of affected tester (no customers): fischer9966@gmail.com
Issue reported by: Applause - Internal Team

Action Performed:

  1. Open Desktop App or go to staging.new.expensify.com
  2. Login with any account
  3. Go to any chat
  4. Click Emoji icon in Composer
  5. Use "Tab" key to select any emoji category icon
  6. Press "Enter" key

Expected Result:

The emoji list scrolls to the selected category

Actual Result:

Nothing happens when user press "Enter" key on emoji category icon

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Bug6630237_1728526095969.Web-Emoji-Picker-Category-Select-with-keys.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021846197861822341766
  • Upwork Job ID: 1846197861822341766
  • Last Price Increase: 2024-10-15
  • Automatic offers:
    • ahmedGaber93 | Reviewer | 104450544
Issue OwnerCurrent Issue Owner: @ahmedGaber93
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 10, 2024
Copy link

melvin-bot bot commented Oct 10, 2024

Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@lanitochka17
Copy link
Author

@trjExpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@bernhardoj
Copy link
Contributor

bernhardoj commented Oct 10, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

Pressing Enter doesn't do anything on the emoji category button.

What is the root cause of that problem?

In the emoji picker menu code, we have a keydown listener which calls prevent default when we press ENTER.

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;
}

Then, we also have an ENTER shortcut which also enables the prevent default.

useKeyboardShortcut(
CONST.KEYBOARD_SHORTCUTS.ENTER,
(keyBoardEvent) => {
if (!(keyBoardEvent instanceof KeyboardEvent) || isEnterWhileComposition(keyBoardEvent) || keyBoardEvent.key !== CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey) {
return;
}
// Select the currently highlighted emoji if enter is pressed
let indexToSelect = focusedIndex;
if (highlightFirstEmoji) {
indexToSelect = 0;
}
const item = filteredEmojis.at(indexToSelect);
if (indexToSelect === -1 || !item) {
return;
}
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);
}
},
{shouldPreventDefault: true, shouldStopPropagation: true},
);

The code in the shortcut was previously in the keydown listener. So, the issue is, that we always prevent default when ENTER without checking whether there is any emoji currently being highlighted or not. So, pressing ENTER on the emoji category does nothing.

What changes do you think we should make in order to solve the problem?

Remove the prevent default and stop propagation from the keydown listener,

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;
}

and move it inside the ENTER shortcut and call it if there is a highlighted emoji, just like how it was before.

const item = filteredEmojis.at(indexToSelect);
if (indexToSelect === -1 || !item) {
return;
}
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);
}
},
{shouldPreventDefault: true, shouldStopPropagation: true},

And set the shouldPreventDefault to false and remove shouldStopPropagation.

After applying the solution, we still have another case to fix as mentioned here.
For that case, when we search for emoji, we will highlight the first emoji (setHighlightFirstEmoji).

if (normalizedSearchTerm === '') {
// There are no headers when searching, so we need to re-make them sticky when there is no search term
setFilteredEmojis(allEmojis);
setHeaderIndices(headerRowIndices);
setFocusedIndex(-1);
setHighlightEmoji(false);
return;
}
// Remove sticky header indices. There are no headers while searching and we don't want to make emojis sticky
setFilteredEmojis(newFilteredEmojiList ?? []);
setHeaderIndices([]);
setHighlightFirstEmoji(true);

However, when clearing the search keyword, we don't reset the highlight state. So, when pressing enter, the index item will be 0. And because index 0 is a header, no emoji will be selected and prevent default is still called.

let indexToSelect = focusedIndex;
if (highlightFirstEmoji) {
indexToSelect = 0;
}
const item = filteredEmojis.at(indexToSelect);
if (indexToSelect === -1 || !item) {
return;
}
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);
}

To fix it, we should reset the highlight first state back when clearing the search keyword here.

setHighlightFirstEmoji(false);

And, we can move the prevent default inside the if,

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);
}

so we will only prevent the default when an emoji will be selected.

@trjExpensify
Copy link
Contributor

Why was it moved in the first place?

@trjExpensify
Copy link
Contributor

Looking at the regression test linked in the OP, it's a bit ambiguous that pressing enter there should jump to the emoji category:

  1. Open the emoji picker
  2. Press the down arrow key multiple times to reach the ""Animals & Nature"" category
  3. Verify the highlighted emoji is visible on the screen with every key press.
  4. Press the up arrow key multiple times to reach the top row of the emojis
  5. Verify the highlighted emoji is visible on the screen with every key press.
  6. Double click any emoji in the list
  7. Verify that the emoji is inserted only once in the composer
  8. Send the emoji
  9. Hover over the emoji in the conversation history
  10. Verify tooltip displays an enlarged emoji and the emoji name

@bernhardoj
Copy link
Contributor

bernhardoj commented Oct 12, 2024

Why was it moved in the first place?

It's to fix this issue: #47272
The reason is explained here: #47272 (comment)

Basically, we have 2 ENTER shortcuts (Form and Emoji Picker) which are subscribed in a different way.

@melvin-bot melvin-bot bot added the Overdue label Oct 14, 2024
Copy link

melvin-bot bot commented Oct 14, 2024

@trjExpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@trjExpensify trjExpensify added the External Added to denote the issue can be worked on by a contributor label Oct 15, 2024
@melvin-bot melvin-bot bot changed the title Web/Desktop - Emoji Picker - Nothing happens when user press "Enter" on emoji category icon [$250] Web/Desktop - Emoji Picker - Nothing happens when user press "Enter" on emoji category icon Oct 15, 2024
Copy link

melvin-bot bot commented Oct 15, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021846197861822341766

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 15, 2024
Copy link

melvin-bot bot commented Oct 15, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @ahmedGaber93 (External)

@melvin-bot melvin-bot bot removed the Overdue label Oct 15, 2024
@trjExpensify
Copy link
Contributor

Hm okay, CC: @Krishna2323 @rayane-djouah for vis that the fix for that apparently broke this.

@trjExpensify
Copy link
Contributor

@ahmedGaber93 can you review this proposal, please? Thanks!

@siddhakdak
Copy link

can i start work on this issue..

@siddhakdak
Copy link

/assign

@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Oct 16, 2024

@bernhardoj Thanks for the proposal
Your RCA seem correct, and the solution works good, but can you check this case before move forward.

  1. Open the picker and type any letter, e.g. "s" then remove it (confirm the mouse pointer is out of the picker and not hover on any emoji while reproducing)
  2. Try to reproduce the issue
20241015185548339.mp4

@bernhardoj
Copy link
Contributor

Updated my proposal to fix that

@ahmedGaber93
Copy link
Contributor

@bernhardoj's proposal LGTM!

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Oct 16, 2024

Triggered auto assignment to @aldo-expensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 16, 2024
Copy link

melvin-bot bot commented Oct 16, 2024

📣 @ahmedGaber93 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Oct 17, 2024
@bernhardoj
Copy link
Contributor

PR is ready

cc: @ahmedGaber93

@aldo-expensify
Copy link
Contributor

@trjExpensify , I think we should also include this in the scope of this issue: #50971 (comment), otherwise just fixing the ENTER in the category is a bit useless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
Development

No branches or pull requests

6 participants