-
Notifications
You must be signed in to change notification settings - Fork 81
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
Refactor handleKeydown Method for Improved Readability and Maintainability #804
base: develop
Are you sure you want to change the base?
Refactor handleKeydown Method for Improved Readability and Maintainability #804
Conversation
Hi @MisRob & @BabyElias, kindly review it. |
@shivam-daksh Can you please update the Changelog in description with all the fields that were originally in the template? Also, please run the |
@BabyElias, I've updated the changelog section in description. Please have a look at it. |
@shivam-daksh The Changelog looks good 👍 For the linter - maybe try |
Hey @BabyElias, I've just passed the linting test by commenting the unsued code. Could you please review it now? |
Hey @shivam-daksh , good work overall :)
Don't know if you have an idea about the playground page yet to test your changes or not, you can have a look at it here. This comes in extremely handy to preview the output for code changes as and when they are done. |
Hi @BabyElias , |
Hey @shivam-daksh :)
Thanks! |
Hey @BabyElias , Please review it again. |
@shivam-daksh The Tab key behaviour is as expected now, great job there! Also, I was having a look at the code, and I could see that a number of comments that existed earlier have been removed by the new commits. We try to keep our code as well documented and easy to understand as possible so that it can be easier for future contributors to make sense of the code-base and contribute in a better way, especially with something as complicated as the |
Hi @BabyElias, Thanks for the reminding! I’ve re-added the lost comments during the refactoring to help clarify the code for future contributors. Regarding the Shift+Tab functionality, I’m a bit unclear on how it should be working differently. As far as I can tell, its behavior remains the same as before the refactor. If you could provide a little visual help or specific examples of what you expect, that would really help me address the issue effectively! Looking forward to your input! Screen.Recording.2024-10-27.at.3.59.11.PM.mov |
@shivam-daksh, |
@BabyElias, Okay. I'm sorry. Totally misunderstood that 😆 . |
Thanks @shivam-daksh for this work and @BabyElias for taking care of the review, we really appreciate it :) |
No worries, @shivam-daksh. The table has many features that are not immediately obvious, we're currently discussing how to document technical requirements, including a11y, in detail, to guide future work on more complex components. Meanwhile, fortunately @BabyElias and @radinamatic have everything in their mind. |
Hi @shivam-daksh, no time pressure around this task, just checking in if there's anything you'd need since it seems some aspects are a bit tricky. I also noted @BabyElias's
and if that'd help, I could try to do the recording for you |
@BabyElias and @MisRob, I am really sorry for extending that long. My exams are going on. However, I will finish it at end of this week. |
@shivam-daksh Really please take all the time you need - it's absolutely fine for volunteers to work on tasks for longer periods of time - weeks, even months. Most of our 'help wanted' are intentionally not time sensitive, and for those that are, we'd inform volunteers beforehand. You're generously volunteering your time and energy and there's really no need to make it into feeling bad! I hope you can focus on your exams and don't forget to get plenty of rest ;) I'm glad to hear that the expectations are clearer. Thanks @BabyElias for all the guidance for @shivam-daksh. |
…ksh/kolibri-design-system into refactor-handlekeydown merging refactor-handlekeydown
Hey @BabyElias, please have a look at this. |
Hey @shivam-daksh, so happy to see all the pieces finally put together! |
Wonderful work here @shivam-daksh and @BabyElias. As agreed with @BabyElias, @AlexVelezLl will join us here to offer second eyes for the code as soon as all @BabyElias's feedback is resolved. I will then prepare test environment for our QA team in Kolibri. |
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.
Thank you @shivam-daksh! This is looking good. I have left some minor comments on small things I noticed. Please let me know if you have any questions :)
lib/KTable/index.vue
Outdated
const nextCell = this.getCell(nextRowIndex, nextColIndex); | ||
const nextFocusableElements = this.getFocusableElements(nextCell); | ||
const nextCellAndFocusableElements = [nextCell, ...nextFocusableElements]; | ||
nextCellAndFocusableElements[0].focus(); |
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 do we need this nextCellAndFocusableElements
if we always will be just focusing the index 0? We dont do anything with this array after that. That means that we will be always focusing the nextCell. We dont need to query the focusable elments of the next cell.
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.
Btw in the updateFocusState
we are already focusing the next cell, so there is no need of any of these lines:
const nextCell = this.getCell(nextRowIndex, nextColIndex);
const nextFocusableElements = this.getFocusableElements(nextCell);
const nextCellAndFocusableElements = [nextCell, ...nextFocusableElements];
nextCellAndFocusableElements[0].focus();
Thank you @shivam-daksh! Code changes looks good to me! I will not yet approve this PR since @MisRob will check this with our QA team, but we can have my review as ✔️. I noticed that the issue description mentioned that we needed to add unit tests to this part of the code. I am not sure if you already discussed about this with @BabyElias or @MisRob (I didnt read the whole discussion). But pinging them in case the unit tests are required c:. Thank you! |
The code changes do not introduce any such new functionalities that might need to be covered by new unit tests. So, seems good to go from my end too :) |
Thanks all of you, I will get ready the test Kolibri PR for QA |
@shivam-daksh would you please merge the latest |
@MisRob, I've merged the develop into our current branch. The code is runnnig fine and table is working properly but having a warning in terminal. This happened after merge. js
|
That is just a validator warning since a new PR merged for KTable mandates having a columnID for each header row. Nothing blocking. |
Test PR in Kolibri open here learningequality/kolibri#12914. If QA confirms no regressions, we can merge this work. |
Description
This PR addresses the issue described in Issue #795. The
handleKeydown
method in theKTable
component has been refactored to improve readability and maintainability while preserving the existing functionality and accessibility of the keyboard navigation.Issue addressed
#795
Addresses #PR# HERE
Summary
In #727, we introduced a new component—KTable—which provides a flexible, accessible table layout with enhanced keyboard navigation capabilities. As part of this, the handleKeydown method is responsible for managing keyboard navigation between table cells, handling focus, and managing the arrow, tab, and other keys.
The current implementation of the handleKeydown method has grown more complex over time, making it harder to maintain and reason about. The goal of this issue is to refactor the method into a more readable and maintainable format while preserving the functionality and accessibility of the keyboard navigation.
Changes Made
-- Broke down the logic into smaller, modular methods for handling different key events.
-- Ensured that the Tab key mimics the functionality of the ArrowRight key.
-- Ensured that the Shift+Tab key mimics the functionality of the ArrowLeft key and moves to the last cell when the first cell is focused.
This pull request introduces several enhancements and refactorings to the keyboard navigation and focus management logic in the
KTable
component. The changes improve the handling of various keyboard events and modularize the code for better readability and maintainability.Enhancements to keyboard navigation:
Enter
key for sorting columns andTab
key for navigating between focusable elements within a cell. (lib/KTable/index.vue
)ArrowUp
,ArrowDown
,ArrowLeft
, andArrowRight
keys to simplify and enhance navigation between cells. (lib/KTable/index.vue
)Code modularization:
getNextIndexes
,handleTabKey
,moveToNextCell
,moveToPreviousCell
, andgetFocusableElements
methods to modularize and clean up the main event handler logic. (lib/KTable/index.vue
)Changelog
handleKeydown
method into smaller, modular methods for handling different key events. Ensured that theTab
key mimics the functionality of theArrowRight
key, and theShift+Tab
key mimics the functionality of theArrowLeft
key. Additionally, pressingShift+Tab
when the first cell is focused now moves the focus to the last cell (bottom-right cell).KTable
Steps to test
(optional) Implementation notes
At a high level, how did you implement this?
Does this introduce any tech-debt items?
Testing checklist
Reviewer guidance
Comments