Skip to content

Navigate between tasks using arrow keys ⌨️ #493

Description

@anoopcodehack

Navigate between tasks using arrow keys ⌨️

File: client/src/pages/Dashboard.jsx

No keyboard navigation between tasks 💀
Power users love this fr!!

Fix:
const [focusedTaskIndex, setFocusedTaskIndex] = useState(-1)

useEffect(() => {
const handler = (e) => {
if (e.target.matches('input, textarea')) return
if (e.key === 'ArrowDown') {
setFocusedTaskIndex(i =>
Math.min(i + 1, tasks.length - 1))
}
if (e.key === 'ArrowUp') {
setFocusedTaskIndex(i => Math.max(i - 1, 0))
}
if (e.key === 'Enter' && focusedTaskIndex >= 0) {
setSelectedTask(tasks[focusedTaskIndex])
}
}
window.addEventListener('keydown', handler)
return () => window.removeEventListener('keydown', handler)
}, [tasks, focusedTaskIndex])

// highlight focused task with ring:
// pass focusedTaskIndex to KanbanBoard
// add ring-2 ring-purple-500 when focused

~15 lines! No backend needed 🎯

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions