fix(Tasks): implement hotkeysEnabled state to control keyboard shortcuts
Description
-
Add
enabledparameter to useHotkeys hook with default true value -
Pass hotkeysEnabled state to all useHotkeys calls in Tasks component
-
Add hotkeysEnabled check in manual keyboard handler (ArrowUp/Down/Enter)
-
Add data-testid to tasks table container for testing
-
Add tests for useHotkeys enabled parameter
-
Add tests for hotkeys enable/disable on mouse hover
-
Add active context pattern with
onPointerDownfor tablet/touch support -
Add global pointerdown listener to disable hotkeys on outside click
-
Add tests for active context scenarios
-
Fixes: #425
Checklist
- [x] Ran
npx prettier --write .(for formatting) - [ ] Ran
gofmt -w .(for Go backend) - [x] Ran
npm test(for JS/TS testing) - [x] Added unit tests, if applicable
- [x] Verified all tests pass
- [ ] Updated documentation, if needed
Additional Notes
Video:
https://github.com/user-attachments/assets/1cbae957-8958-4566-947f-7716cf663ebe
Thank you for opening this PR!
Before a maintainer takes a look, it would be really helpful if you could walk through your changes using GitHub's review tools.
Please take a moment to:
- Check the "Files changed" tab
- Leave comments on any lines for functions, comments, etc. that are important, non-obvious, or may need attention
- Clarify decisions you made or areas you might be unsure about and/or any future updates being considered.
- Finally, submit all the comments!
More information on how to conduct a self review: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request
This helps make the review process smoother and gives us a clearer understanding of your thought process.
Once you've added your self-review, we'll continue from our side. Thank you!
@ShivaGupta-14 this looks good but the mouse control check not work in scenarios though. Like for example a tablet with some keyboard. Probably need a better check, instead of this.
thanks @its-me-abhishek! you are right it needs a better check. I researched this and I am planning to use the Active Context approach combined with the current implementation, so it will work on both touch/keyboard devices and with mouse hover.
will push the update soon!
pushed the updated changes! now hotkeys work for mouse hover, clicks, taps, and stylus input
I think just having an active context should suffice for this, not sure though
for task management apps, hover is the standard UX, users don't context-switch like in VS Code, so i think it's better to keep it.
Hi @its-me-abhishek,
Thanks for the suggestion about using Intersection Observer and the package! I did some research on it and found that it detects visibility (whether an element is on screen) rather than user interaction (hover/click).
while this might work fro our current setup with mainly the Tasks table, it could create conflicts when we add the planned features like Kanban, Calendar, and Graph views, since multiple views could be visible simultaneously, causing hotkey conflicts.
regarding device compatibility concerns you mentioned, the current implementation uses pointer events which are well-supported across desktop, mobile, tablets, and stylus devices.
I completely understand your concern about too many states and useEffects in Tasks.tsx, as a solution, I can refactor the current implementation into a reusable useHotkeyScope custom hook. This would:
- reduce the state/effect count in Tasks.tsx
- make it reusable for future views (knban, calendar, graph)
- Keep the logic centralized in one place
would that work better? happy to discuss alternatives if you have other ideas!
Thanks!
@its-me-abhishek PTAL :)