-
Notifications
You must be signed in to change notification settings - Fork 3k
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 enter doesn't select the emoji category #50971
Fix pressing enter doesn't select the emoji category #50971
Conversation
@ahmedGaber93 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
App/src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Lines 150 to 161 in c3d33fc
// 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
App/src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Lines 157 to 160 in c3d33fc
// 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.
Lines 7595 to 7598 in c3d33fc
function shouldAutoFocusOnKeyPress(event: KeyboardEvent): boolean { | |
if (event.key.length > 1) { | |
return false; | |
} |
For
App/src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Lines 150 to 155 in c3d33fc
// 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.
App/src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Lines 75 to 87 in c3d33fc
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))) { |
There was a problem hiding this comment.
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
- select the emoji and close the menu
- 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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👁️
There was a problem hiding this comment.
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.
Bug: the first emoji on the selected category is not autofocused after selecting the category like what we do in search emoji.
Expected: after selecting any category, first emoji of it should be focused and arrow-left and arrow-right should move focusing between category emojis. Current: the first emoji on the selected category is not autofocused after selecting the category and arrow-left and arrow-right do nothing (instead the first emoji on the first category not the selected category is focused) 20241018122154891.mp4I think this feature is not broken, but it is not implemented before. |
Yes, it was never implemented, so it's not a bug. |
Reviewer Checklist
Screenshots/VideosAndroid: Nativea.mp4Android: mWeb Chromeaw.mp4iOS: Nativei.mp4iOS: mWeb Safariiw.mp4MacOS: Chrome / Safariw.mp4MacOS: Desktopd.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just need a confirmation here #50971 (comment)
I will report this bug #50971 (comment) in slack after deploying this PR to staging |
So, I've testing this and this seems to be pretty important: #50971 (comment) Once you select a category using the keyboard, it is not possible to choose emojis properly unless we go with the mouse. Then, being able to scroll by hitting enter on the category becomes somewhat pointless if your intention was to navigate with the keyboard. I'm inclined to consider this as part of the scope of the work being done here. |
Makes sense to me. 👍 |
It feels more like a missing feature, luckily it's very simple to do. Here is how it looks web.mp4 |
Thank you @bernhardoj , it works pretty well now. Screen.Recording.2024-10-25.at.12.33.04.PM.mov
If you are hinting there should be extra compensation, feel free to request in the right channel (I'm not sure which one is the right channel :) ) |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/aldo-expensify in version: 9.0.55-0 🚀
|
🚀 Deployed to production by https://github.com/Beamanator in version: 9.0.55-10 🚀
|
Details
Pressing ENTER doesn't select the emoji category in emoji picker.
Fixed Issues
$ #50561
PROPOSAL: #50561 (comment)
Tests
Same as QA Steps
Offline tests
Same as QA Steps
QA Steps
iOS: no keyboard shortcut
Android: no keyboard shortcut either, but it natively supports it
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
android.mp4
Android: mWeb Chrome
android.mweb.mp4
iOS: Native
iOS: mWeb Safari
ios.mweb.mp4
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
desktop.mp4