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

[HOLD for payment 2023-10-02] [$1000] Web- Action menu - Unable to navigate options in Action menu using Arrow keys #23280

Closed
1 of 6 tasks
kbecciv opened this issue Jul 20, 2023 · 58 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kbecciv
Copy link

kbecciv commented Jul 20, 2023

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


Action Performed:

  1. Go to site
  2. Open a conversation
  3. Click on a chat
  4. Open action menu
  5. Use arrow keys and TAB to navigate
  6. Tap FAB
  7. Use Arrow Keys and TAB to navigate

Expected Result:

Like in FAB, user must be able to navigate using both arrow keys and TAB button.

Actual Result:

On pressing FAB, user can navigate through options using both arrow keys and TAB button. In Action Menu, user can navigate only using TAB . He cannot use arrow keys and navigate through options in Action menu,

Workaround:

Unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.43-3
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
Notes/Photos/Videos: Any additional supporting documentation

Bug6135278_tab.mp4

Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01eeba1242aba22472
  • Upwork Job ID: 1682468481034489856
  • Last Price Increase: 2023-07-21
  • Automatic offers:
    • situchan | Contributor | 26241505
    • samh-nl | Contributor | 26748431
@kbecciv kbecciv added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 20, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 20, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jul 20, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@samh-nl
Copy link
Contributor

samh-nl commented Jul 20, 2023

Proposal

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

The report action context menu cannot be navigated through the arrow keys, while the FAB can.

What is the root cause of that problem?

The FAB relies on the PopoverMenu component, which implements the useArrowKeyFocusManager hook to modify the focused menu index when the arrow keys are pressed:

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: -1, maxIndex: props.menuItems.length - 1, isActive: props.isVisible});

However, the context menu of report actions does not implement such functionality.

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

Similar to the FAB, the arrow keys should be registered and used to determine the focused menu item.

This involves the following changes:

  1. Add useArrowKeyFocusManager to BaseReportActionContextMenu, e.g.:
const shouldEnableArrowNavigation = !props.isMini && (props.isVisible || shouldKeepOpen);
const filteredContextMenuActions = _.filter(ContextMenuActions, shouldShowFilter);

// Context menu actions that are not rendered as menu items are excluded from arrow navigation
const nonMenuItemActionIndexes = _.map(filteredContextMenuActions, (contextAction, index) => _.isFunction(contextAction.renderContent) ? index : undefined);
const disabledIndexes = _.filter(nonMenuItemActionIndexes, (index) => !_.isUndefined(index));

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
    initialFocusedIndex: -1,
    disabledIndexes,
    maxIndex: filteredContextMenuActions.length - 1,
    isActive: shouldEnableArrowNavigation,
});
  1. Add focused prop to ContextMenuItem (default false).
  2. Inside ContextMenuItem, the focused prop should be passed down to MenuItem
  3. Select the focused item on enter. For this, we abstract the onPress handler to a function.
const selectItem = (contextAction) => {
    interceptAnonymousUser(() => contextAction.onPress(closePopup, payload), contextAction.isAnonymousAction);
};

useKeyboardShortcut(
	CONST.KEYBOARD_SHORTCUTS.ENTER,
	() => {
		if (focusedIndex === -1) {
			return;
		}
		selectItem(filteredContextMenuActions[focusedIndex]);
		setFocusedIndex(-1);
	},
        {isActive: shouldEnableArrowNavigation},
);

What alternative solutions did you explore? (Optional)

N/A

@maddylewis maddylewis added the External Added to denote the issue can be worked on by a contributor label Jul 21, 2023
@melvin-bot melvin-bot bot changed the title Web- Action menu - Unable to navigate options in Action menu using Arrow keys [$1000] Web- Action menu - Unable to navigate options in Action menu using Arrow keys Jul 21, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 21, 2023

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 21, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 21, 2023

Current assignee @maddylewis is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Jul 21, 2023

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

@0xmiros
Copy link
Contributor

0xmiros commented Jul 21, 2023

@samh-nl can you please provide implementation detail? i.e. where to put useArrowKeyFocusManager in which component?

@IftikharNadeem12
Copy link

import React, { useRef, useEffect } from 'react';
import { View, TouchableOpacity, Text, Keyboard } from 'react-native';

const ChatComponent = () => {
const item1Ref = useRef(null);
const item2Ref = useRef(null);
// Add more refs for other menu items if needed

useEffect(() => {
const handleArrowKeyPress = (event) => {
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
// Prevent default arrow key behavior, such as scrolling
event.preventDefault();

    // Get the currently focused element
    const currentlyFocusedItem = item1Ref.current || item2Ref.current;
    if (!currentlyFocusedItem) return;

    // Find the next focusable element based on the Arrow key pressed
    const nextFocusableItem = event.key === 'ArrowDown' ? item2Ref.current : item1Ref.current;

    // Focus the next element
    if (nextFocusableItem) {
      nextFocusableItem.focus();
    }
  }
};

// Add event listener for keydown
Keyboard.addListener('keydown', handleArrowKeyPress);

// Clean up the event listener on component unmount
return () => {
  Keyboard.removeListener('keydown', handleArrowKeyPress);
};

}, []);

// Your chat component code with TouchableOpacity for each menu item
};

@melvin-bot
Copy link

melvin-bot bot commented Jul 21, 2023

📣 @IftikharNadeem12! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  2. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  3. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@IftikharNadeem12
Copy link

import React, { useRef, useEffect } from 'react';
import { View, TouchableOpacity, Text, Keyboard } from 'react-native';

const ChatComponent = () => {
const item1Ref = useRef(null);
const item2Ref = useRef(null);
// Add more refs for other menu items if needed

useEffect(() => {
const handleArrowKeyPress = (event) => {
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
// Prevent default arrow key behavior, such as scrolling
event.preventDefault();

    // Get the currently focused element
    const currentlyFocusedItem = item1Ref.current || item2Ref.current;
    if (!currentlyFocusedItem) return;

    // Find the next focusable element based on the Arrow key pressed
    const nextFocusableItem = event.key === 'ArrowDown' ? item2Ref.current : item1Ref.current;

    // Focus the next element
    if (nextFocusableItem) {
      nextFocusableItem.focus();
    }
  }
};

// Add event listener for keydown
Keyboard.addListener('keydown', handleArrowKeyPress);

// Clean up the event listener on component unmount
return () => {
  Keyboard.removeListener('keydown', handleArrowKeyPress);
};

}, []);

// Your chat component code with TouchableOpacity for each menu item
};

**My Upwork Profile is;

Iftikhar Nadeem**

https://www.upwork.com/freelancers/iftikharnadeem

@IftikharNadeem12
Copy link

Contributor Details;

My Expensify account email: ijweaver2004@gmail.com
My Upwork Profile Link;

https://www.upwork.com/freelancers/iftikharnadeem

@jscardona12
Copy link
Contributor

jscardona12 commented Jul 21, 2023

Proposal

Problem:

Implement Keyboard Navigation for Context Menu

The current implementation of the BaseReportActionContextMenu component lacks keyboard navigation support using arrow keys. As a result, users who rely on keyboard input are unable to easily navigate through the context menu options, leading to a subpar user experience and accessibility issues.

Root Cause:

The root cause of the problem is the absence of event listeners and handling for keyboard events in the BaseReportActionContextMenu component. Without capturing arrow key presses, the component cannot update the selected index of the context menu options or apply a selected style to the corresponding menu item, hindering keyboard navigation.

Solution:

To solve the problem and enable keyboard navigation, we propose the following changes to the BaseReportActionContextMenu component:

  1. Event Listeners for Keyboard Events:

    • Implement event listeners for the 'keydown' event on the component. These event listeners will capture keyboard input, allowing us to respond to arrow key presses.
  2. Handle Arrow Key Presses:

    • In the event handler for the 'keydown' event, specifically check for arrow key presses (ArrowUp and ArrowDown).
    • Prevent the default behavior of the arrow keys to avoid unintended scrolling or other interactions.
  3. Update Selected Index:

    • Track the selected index of the context menu options within the component's state.
    • When an arrow key is pressed, update the selected index accordingly, ensuring it stays within the bounds of the available menu options.
  4. Apply Selected Style:

    • Modify the rendering of the context menu items to apply a selected style to the item corresponding to the current selected index.
    • This can be achieved through the use of the isSelected prop passed to the ContextMenuItem component or by applying specific styles to the selected menu item.

Implementation Details:

Implementation Details Code

Working Solution:

Screen.Recording.2023-07-21.at.4.40.40.PM.mov

@jscardona12
Copy link
Contributor

Hi @0xmiroslav, let me know what do you think about the above Proposal.

Thanks!

@samh-nl
Copy link
Contributor

samh-nl commented Jul 21, 2023

@0xmiroslav I think it makes more sense to hold till BaseReportActionContextMenu has been migrated to a functional component, so that the useArrowFocusManager hook can be used here. Little point in re-implementing the same logic if we know it will be migrated in #16259. Implementing it separately would only mean we will have to undo and wouldn't be an elegant solution.

The migration has not been assigned to anyone yet and it's a small component, so it could be combined with this issue perhaps? I was planning on making it a functional component anyway for this proposal, but there's already an issue for that so please advise.

@maddylewis
Copy link
Contributor

waiting for an update on @samh-nl's question here - #16259 (comment)

@melvin-bot melvin-bot bot removed the Overdue label Jul 24, 2023
@0xmiros
Copy link
Contributor

0xmiros commented Jul 24, 2023

Agreed. I asked confirmation here - #16259 (comment)

@marcaaron
Copy link
Contributor

yes, I would recommend we HOLD this issue on #16259

@melvin-bot melvin-bot bot added the Overdue label Jul 26, 2023
@maddylewis maddylewis added Weekly KSv2 and removed Daily KSv2 labels Jul 27, 2023
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels Sep 20, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 22, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @samh-nl got assigned: 2023-09-19 06:43:32 Z
  • when the PR got merged: 2023-09-22 08:41:02 UTC
  • days elapsed: 3

On to the next one 🚀

@francoisl
Copy link
Contributor

Reposting @situchan's message regarding the bonus from the PR here:

There's 2 hrs delay from bonus timeline but it would be much appreciated if it's still eligible unless any regression found. The delay was just from variable name change and @samh-nl was sleeping at that moment. cc: @francoisl

@maddylewis do you know if we have any precedent in a situation like this?

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Sep 25, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Web- Action menu - Unable to navigate options in Action menu using Arrow keys [HOLD for payment 2023-10-02] [$1000] Web- Action menu - Unable to navigate options in Action menu using Arrow keys Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.73-1 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-10-02. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@situchan] The PR that introduced the bug has been identified. Link to the PR:
  • [@situchan] 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:
  • [@situchan] 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:
  • [@situchan] Determine if we should create a regression test for this bug.
  • [@situchan] 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.
  • [@maddylewis] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Oct 1, 2023
@maddylewis
Copy link
Contributor

maddylewis commented Oct 2, 2023

Payments

  • Reporting bonus: N/A
  • Contributor: @samh-nl ($1k via Upwork)
  • C+: @situchan ($1k via Upwork)

@maddylewis
Copy link
Contributor

@situchan will you review this checklist when you have a chance? #23280 (comment)

@situchan
Copy link
Contributor

situchan commented Oct 2, 2023

This is kind of feature request than bug

@situchan
Copy link
Contributor

situchan commented Oct 2, 2023

Regression Test Proposal (web/desktop only)

  1. Go to any chat that has a message
  2. Right-click the message
  3. Verify that context menu opens
  4. Repeat pressing up/down arrows from keyboard
  5. Verify that selected option changes based on arrow key
  6. Verify that first option is selected on Down press when last option is selected
  7. Verify that last option is selected on Upon press when first option is selected
  8. Press Enter on any selected option
  9. Verify that it triggers action of selected option correctly and context menu closes

@maddylewis
Copy link
Contributor

offers sent 👍

@situchan
Copy link
Contributor

situchan commented Oct 2, 2023

@maddylewis Accepted, thanks. Can you also please check bonus eligibility?

@maddylewis
Copy link
Contributor

included bonus

@maddylewis
Copy link
Contributor

@situchan - i think i paid you twice. i'll request a refund for the $1k payment.

@situchan
Copy link
Contributor

situchan commented Oct 2, 2023

@maddylewis can we use that 1k for #24610 which is due payment for more than a month?

@samh-nl
Copy link
Contributor

samh-nl commented Oct 2, 2023

Much appreciated, thanks.

@maddylewis
Copy link
Contributor

haha, yes for sure!

@maddylewis
Copy link
Contributor

confirmed here that the double payment can be used for the outstanding issue here - #24610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

9 participants