App icon indicating copy to clipboard operation
App copied to clipboard

[$500] The back and forward keys are not working properly for navigating back to a characters

Open m-natarajan opened this issue 1 year ago β€’ 5 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 1.4.38-0 Reproducible in staging?: y Reproducible in production?: y If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: Applause internal team Slack conversation:

Action Performed:

  1. Open the emoji picker
  2. Enter characters in the search field
  3. Use the back and forward keys

Expected Result:

The back and forward keys should navigate characters entered in the emoji picker's search field

Actual Result:

The back and forward keys are not working properly for navigating back to a character while in use

Workaround:

unknown

Platforms:

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

  • [ ] Android: Native
  • [ ] Android: mWeb Chrome
  • [ ] iOS: Native
  • [ ] iOS: mWeb Safari
  • [x] MacOS: Chrome / Safari
  • [x] MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/Expensify/App/assets/38435837/5328b0c4-0493-4fe0-8136-50305c85c004

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a4bbd031958bf120
  • Upwork Job ID: 1755301304657534976
  • Last Price Increase: 2024-02-07

m-natarajan avatar Feb 07 '24 18:02 m-natarajan

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

melvin-bot[bot] avatar Feb 07 '24 18:02 melvin-bot[bot]

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

melvin-bot[bot] avatar Feb 07 '24 18:02 melvin-bot[bot]

Triggered auto assignment to @miljakljajic (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

melvin-bot[bot] avatar Feb 07 '24 18:02 melvin-bot[bot]

Proposal

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

The back and forward keys are not working properly for navigating back to a characters

What is the root cause of that problem?

The main problem with issue is that on EmojiPickerMenu screen we are using useArrowKeyFocusManager which is disabled using arrow keys when index of element is -1 And when input is active,useArrowKeyFocusManager does not allow us to interact with the input

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

To fix this issue we can update useArrowKeyFocusManager and add new param enabledKeyboards and pass isActive param And when we have focused input we will have only enabled the up and down button in ArrowKeyFocusManager because enabledKeyboards: [CONST.KEYBOARD_SHORTCUTS.ARROW_UP, CONST.KEYBOARD_SHORTCUTS.ARROW_DOWN] From the other side left and right will be disabled for the emoji list As a result, events will work as intended

https://github.com/Expensify/App/blob/82fa188a2df93862d35995fddfaf19e38e8fd490/src/components/EmojiPicker/EmojiPickerMenu/index.js#L103-L111

    const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
        maxIndex: filteredEmojis.length - 1,
        // Spacers indexes need to be disabled so that the arrow keys don't focus them. All headers are hidden when list is filtered
        disabledIndexes,
        itemsPerRow: CONST.EMOJI_NUM_PER_ROW,
        initialFocusedIndex: -1,
        disableCyclicTraversal: true,
        onFocusedIndexChange,
        enabledKeyboards: [CONST.KEYBOARD_SHORTCUTS.ARROW_UP, CONST.KEYBOARD_SHORTCUTS.ARROW_DOWN],
        isActive: !isFocused,
    });

And then we need update useArrowKeyFocusManager

Add enabledKeyboards = CONST.EMPTY_ARRAY in params

Update arrowConfig

const arrowConfig = useCallback(
    (isAlwaysActive?: boolean) => ({
        excludedNodes: shouldExcludeTextAreaNodes ? ['TEXTAREA'] : [],
        isActive: isAlwaysActive || isActive,
    }),
    [isActive, shouldExcludeTextAreaNodes],
);

https://github.com/Expensify/App/blob/61287bc4e41c39f25a433bfbe2ba063d904dd111/src/hooks/useArrowKeyFocusManager.ts#L47-L53

And update all useKeyboardShortcut

For example CONST.KEYBOARD_SHORTCUTS.ARROW_UP

  useKeyboardShortcut(
    CONST.KEYBOARD_SHORTCUTS.ARROW_UP,
    arrowUpCallback,
    arrowConfig(enabledKeyboards.includes(CONST.KEYBOARD_SHORTCUTS.ARROW_UP)),
);


https://github.com/Expensify/App/blob/61287bc4e41c39f25a433bfbe2ba063d904dd111/src/hooks/useArrowKeyFocusManager.ts#L87

What alternative solutions did you explore? (Optional)

NA

ZhenjaHorbach avatar Feb 07 '24 19:02 ZhenjaHorbach

Proposal

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

The back and forward keys are not working properly for navigating back to a characters

What is the root cause of that problem?

Inside EmojiPickerMenuWithRef we use useArrowKeyFocusManager which catches the arrow key presses and focuses on the emojis instead of changing the input selection.

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

We need to disable the horizontal key presses when input is focused and we have some text in input. This way we can still use left/right arrow keys if the input is empty.

Steps to solve the bug:

  1. Introduce a state for storing input text.
const [inputText, setInputText] = useState('');
  1. Introduce a new parameter inside useArrowKeyFocusManager called shouldDisableHorizontalKeys and set initial value to false.
disableHorizontalKeys?:boolean;
disableHorizontalKeys = false,
  1. Create a new config for horizontal arrow key presses, arrowConfigHorizontalKeys.
    const arrowConfigHorizontal = useMemo(
        () => ({
            excludedNodes: shouldExcludeTextAreaNodes ? ['TEXTAREA'] : [],
            isActive: isActive && !disableHorizontalKeys,
        }),
        [isActive, shouldExcludeTextAreaNodes, disableHorizontalKeys],
    );
  1. Use arrowConfigHorizontalKeys for ARROW_LEFT & ARROW_RIGHT.
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ARROW_LEFT, arrowLeftCallback, arrowConfigHorizontal);
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ARROW_RIGHT, arrowRightCallback, arrowConfigHorizontal);
  1. From EmojiPickerMenu pass disableHorizontalKeys: isFocused && inputText.length to useArrowKeyFocusManager.
disableHorizontalKeys: isFocused && inputText.length,

Result

https://github.com/Expensify/App/assets/85894871/8b2ded48-de5c-42f3-873e-3b9a475f77ad

Krishna2323 avatar Feb 07 '24 19:02 Krishna2323

Reviewing tomorrow!

jjcoffee avatar Feb 08 '24 15:02 jjcoffee

While both proposals are similar, I prefer @Krishna2323's proposal as it offers a much clearer solution.

One thing though, I think we're not so bothered about the right arrow key navigating from the text input to the first emoji, so we may be able to just leave out the useState parts of the proposal that enable that when the text input is empty. Apart from reducing reliance on state, this also ensures consistent behaviour since otherwise you'd be able to navigate to the emojis using the right arrow only when the input is empty, which could be a little confusing.

:ribbon::eyes::ribbon: C+ reviewed

jjcoffee avatar Feb 09 '24 15:02 jjcoffee

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

melvin-bot[bot] avatar Feb 09 '24 15:02 melvin-bot[bot]

Assigning @Krishna2323, and +1 to @jjcoffee's note in https://github.com/Expensify/App/issues/36059#issuecomment-1936158792

amyevans avatar Feb 09 '24 19:02 amyevans

πŸ“£ @jjcoffee πŸŽ‰ 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[bot] avatar Feb 09 '24 19:02 melvin-bot[bot]

πŸ“£ @Krishna2323 πŸŽ‰ An offer has been automatically sent to your Upwork account for the Contributor role πŸŽ‰ Thanks for contributing to the Expensify app!

Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review πŸ§‘β€πŸ’» Keep in mind: Code of Conduct | Contributing πŸ“–

melvin-bot[bot] avatar Feb 09 '24 19:02 melvin-bot[bot]

@jjcoffee PR ready for review :)

Krishna2323 avatar Feb 11 '24 07:02 Krishna2323

PR was deployed to production on 15th Feb, this should be ready for payments tomorrow, I guess. Screenshot 2024-02-21 at 2 16 45β€―PM

cc: @miljakljajic

Krishna2323 avatar Feb 21 '24 08:02 Krishna2323

  • The PR that introduced the bug has been identified. Link to the PR: https://github.com/Expensify/App/pull/34581
  • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/App/pull/34581#issuecomment-1956304707
  • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: N/A - just a missed test case
  • Determine if we should create a regression test for this bug. Yes
  • If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

Regression Test Proposal

  1. Open the emoji picker
  2. Enter characters in the search field
  3. Type some text in the search input field
  4. Verify that you can use the left/right arrow keys to move the text cursor
  5. While still focused on the search input use the down key & verify that the focus moves from input to emoji
  6. Verify that you can use left/right, up/down keys to navigate on the emojis

Do we agree πŸ‘ or πŸ‘Ž

jjcoffee avatar Feb 21 '24 10:02 jjcoffee

@amyevans, @jjcoffee, @miljakljajic, @Krishna2323 Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Feb 26 '24 15:02 melvin-bot[bot]

@miljakljajic can you pls start the payment process?

Krishna2323 avatar Feb 26 '24 19:02 Krishna2323

@miljakljajic Friendly bump for payment :bow:

jjcoffee avatar Feb 29 '24 09:02 jjcoffee

Paid - so sorry for the hold up

miljakljajic avatar Feb 29 '24 15:02 miljakljajic