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

IOU - Keyboard arrow keys does not work inside description field #41777

Closed
1 of 6 tasks
izarutskaya opened this issue May 7, 2024 · 7 comments
Closed
1 of 6 tasks

IOU - Keyboard arrow keys does not work inside description field #41777

izarutskaya opened this issue May 7, 2024 · 7 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2

Comments

@izarutskaya
Copy link

izarutskaya commented May 7, 2024

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.71-0
Reproducible in staging?: Y
Reproducible in production?: Y
Found when executing PR : #41291
Logs: https://stackoverflow.com/c/expensify/questions/4856
Issue reported by: Applause-Internal team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Click on FAB > Submit Expense > Enter an amount > Click next
  3. Open the description field
  4. Create multiple new lines
  5. Press keyboard up arrow key to go up the lines

Expected Result:

Cursor jumps to previous line when pressing up arrow

Actual Result:

When user presses on the up arrow key nothing happens

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

Bug6473883_1715095823382.bandicam_2024-05-07_18-25-25-017.mp4

View all open jobs on GitHub

@izarutskaya izarutskaya added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 7, 2024
Copy link

melvin-bot bot commented May 7, 2024

Triggered auto assignment to @stephanieelliott (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.

@izarutskaya
Copy link
Author

We think this issue might be related to the #vip-vsb.

@bernhardoj
Copy link
Contributor

Proposal

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

The arrow up/down key doesn't work in money request description page.

What is the root cause of that problem?

On the confirmation page, we use OptionsSelector which uses ArrowKeyFocusManager. There is currently no logic to unsubscribe the shortcut when the screen is out of focus. So, the arrow up/down key is consumed by the shortcut.

Why did it work before? That's because we are excluding a TEXTAREA element.

[this.props.shouldExcludeTextAreaNodes && 'TEXTAREA'],

However, the description field now is a live markdown input which is a DIV. But instead of excluding specific tag, we should disable the shortcut when the screen is not focused anymore. I think we need a new way to exclude the live markdown input, but I guess that's not the focus of this issue.

OptionsSelector component itself is deprecated and is in progress to be replaced and ArrowKeyFocusManager will also probably be removed, however, this issue also happens in SelectionList. The shortcut is always enabled.

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
initialFocusedIndex: flattenedSections.allOptions.findIndex((option) => option.keyForList === initiallyFocusedOptionKey),
maxIndex: Math.min(flattenedSections.allOptions.length - 1, CONST.MAX_OPTIONS_SELECTOR_PAGE_LENGTH * currentPage - 1),
disabledIndexes: flattenedSections.disabledOptionsIndexes,
isActive: true,

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

In ArrowKeyFocusManager, we can unsub the shortcut when isFocused is false and subscribe it back when isFocused is true.

componentDidUpdate(prevProps) {
if (prevProps.maxIndex === this.props.maxIndex) {
return;
}
if (this.props.focusedIndex > this.props.maxIndex && this.props.shouldResetIndexOnEndReached) {
this.onArrowDownKey();
}
}

if (prevIsFocused && !isFocused) unsubscribe
else if (!prevIsFocused && isFocused) subscribe

Or we can simply return the children here when isFocused is false

function ArrowKeyFocusManager(props) {
const isFocused = useIsFocused();
return (
<BaseArrowKeyFocusManager
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
isFocused={isFocused}
/>
);
}

if (!isFocused) return props.children;

For the selection list fix, we can set the isActive to isFocused

or to !disableKeyboardShortcuts && isFocused just like we did with ctrl+enter here

useKeyboardShortcut(
CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER,
(e) => {
const focusedOption = flattenedSections.allOptions[focusedIndex];
if (onConfirm) {
onConfirm(e, focusedOption);
return;
}
selectFocusedOption();
},
{
captureOnInputs: true,
shouldBubble: !flattenedSections.allOptions[focusedIndex],
isActive: !disableKeyboardShortcuts && isFocused,
},
);

If we want to improve the excludedNodes so it can exclude the live markdown element, we can refactor the excludedNodes code here so it becomes a function and returns a boolean.

const textArea = event.target as HTMLTextAreaElement;
const contentEditable = textArea?.contentEditable;
const nodeName = textArea?.nodeName;
// Early return for excludedNodes
if (callback.excludedNodes.includes(nodeName)) {
return true;
}

if (callback.excludedNodes(textArea)) {
    return true;
}

excludedNodes will return true if it's a live markdown. We can check if textArea is a div with contenteditable and aria-multiline is true. Or maybe we can set an ID to the component and check it's ID instead.

@stephanieelliott
Copy link
Contributor

This is pretty minor and only affects web, I don't think we should prioritize this right now.

@melvin-bot melvin-bot bot added the Overdue label May 13, 2024
Copy link

melvin-bot bot commented May 14, 2024

@stephanieelliott Eep! 4 days overdue now. Issues have feelings too...

Copy link

melvin-bot bot commented May 16, 2024

@stephanieelliott Still overdue 6 days?! Let's take care of this!

@stephanieelliott
Copy link
Contributor

Oops, had meant to close as not a priority

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. Daily KSv2
Projects
None yet
Development

No branches or pull requests

3 participants