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

Improve the reverse navigation order of focusable elements within KTable cells #840

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

shivam-daksh
Copy link
Contributor

Description

This pull request addresses an issue with the Shift+Tab key navigation behavior in the KTable component (follow-up to issue #795). Previously, pressing Shift+Tab to navigate backward through table cells did not follow the expected reverse order of focusable elements, leading to an unintuitive and confusing user experience.

Issue addressed

#837

Addresses #PR# HERE
#795

Before/after videos:

Before:
View actual behavior video

After:
View expected behavior video

Example:

Given a table with the following structure:

  • Row 1:

    • Cell 1
    • Cell 2
    • Cell 3 containing:
      • Button 1
      • Button 2
  • Row 2:

    • Cell 1 (current focus)
    • Cell 2
    • Cell 3 containing:
      • Button 1
      • Button 2

Expected Behavior:

  • When using Shift+Tab, the focus should move backward through the focusable elements within each table cell in reverse DOM order.
  • For example, if the focus is on Cell 1 in Row 2, pressing Shift+Tab should move the focus to Button 2 inside Cell 3 of Row 1, then to Button 1, then to Cell 3, and so on.

Changes Made:

  • Modified the handleTabKey function to ensure that Shift+Tab navigation moves the focus through focusable elements in reverse DOM order.
  • Corrected the behavior to ensure that pressing Shift+Tab from a focusable element moves focus to the previous focusable element within the cell, and continues navigating through the table cells in reverse order.
  • Removed the unintended Cell 4 from the example in the associated issue description for clarity.

Changelog

Steps to Test:

  1. Open the KTable component with multiple rows and focusable elements within cells (e.g., buttons).
  2. Focus on a cell (e.g., Cell 1 of Row 2).
  3. Press Shift+Tab and verify that the focus moves to the correct previous focusable element (e.g., Button 2 inside Cell 3 of Row 1).
  4. Continue pressing Shift+Tab and verify that focus correctly moves through the elements in reverse order, respecting the DOM structure.

(optional) Implementation notes

At a high level, how did you implement this?

Initially focusCell in updateFocusState method was causing diffculty in implementation of the ideal navigation. It can be tackled by introducing a third parameter in updateFocusState to check if focusCell is necessary or not.

Code

      updateFocusState(nextRowIndex, nextColIndex, shouldFocusCell = true) {
        this.focusedRowIndex = nextRowIndex === -1 ? null : nextRowIndex;
        this.focusedColIndex = nextColIndex;
        this.highlightHeader(nextColIndex);

        if (shouldFocusCell) {
          this.focusCell(nextRowIndex, nextColIndex);
        }
      },
            const prevCellAndFocusableElements = [prevCell, ...prevFocusableElements];
            prevCellAndFocusableElements[prevCellAndFocusableElements.length - 1].focus();
            this.updateFocusState(nextRowIndex, nextColIndex, false);
            event.preventDefault();

Does this introduce any tech-debt items?

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical and brittle code paths are covered by unit tests
  • The change is described in the changelog section above

Reviewer guidance

  • Is the code clean and well-commented?
  • Are there tests for this change?
  • Are all UI components LTR and RTL compliant (if applicable)?
  • Add other things to check for here

Comments

@shivam-daksh
Copy link
Contributor Author

@MisRob and @BabyElias , Please have a look at it.

@BabyElias
Copy link
Contributor

BabyElias commented Nov 22, 2024

@shivam-daksh , The overall working looks nicee to me now. Thanks :)
This PR contains all commits that the #804 PR about Refactoring handlekeydown has. So, I was just wondering if we should consider both the PRs or just this one for both the issues and have QA and further performance reviews for this PR itself? Opinions on this @MisRob?

getFocusableElements(cell) {
if (!cell) return [];
const selectors = 'button, a, input, select, textarea';
return Array.from(cell.querySelectorAll(selectors));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the use of querySelectorAll here, I was actually having a little lag in the navigation behaviour when moving through the focusable elements - this reminded me of an earlier code review comment here. We were using querySelectorAll earlier as well, but it caused performance issues, so we shifted to getElementByTagname and it had a very positive impact on the same. Can you update this code to make use of the previous getElementbyTagname logic? or maybe if there's any other conclusion you derive from that conversation about performance improvement- it is more than welcome. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BabyElias, Thanks for noticing. I've changed it to getElementsByTagName.

@shivam-daksh
Copy link
Contributor Author

shivam-daksh commented Nov 22, 2024

I was just wondering if we should consider both the PRs or just this one for both the issues and have QA and further performance reviews for this PR itself? Opinions on this @MisRob?

@BabyElias , I was thinking the same. Let's leave it to @MisRob what she decides.

@MisRob
Copy link
Member

MisRob commented Nov 22, 2024

Thanks @shivam-daksh and @BabyElias.

Since the first PR review is almost complete, I would recommend to wait until we finish QA and merge #804. Then @shivam-daksh you could rebase this PR on top of the latest develop which will only keep the new diff.

@MisRob MisRob added the TODO: needs review Waiting for review label Nov 22, 2024
@MisRob MisRob self-assigned this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants