Skip to content

Commit

Permalink
Added keyboard shortcuts for adding tasks and submitting edits (fixes…
Browse files Browse the repository at this point in the history
… issue Groverio#18)
  • Loading branch information
mudasirmurtaza committed Oct 17, 2024
1 parent 9de432e commit 65d2810
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,20 @@ document.addEventListener('DOMContentLoaded', () => {
const inputNameElement = document.querySelector('.js-name-input');
inputNameElement.focus();

// Add event listener for "Enter" key to trigger add or edit
document.querySelector('.js-name-input').addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
if (isEditing) {
// If in edit mode, call addTodo to update the task
addTodo();
} else {
// If not in edit mode, call addTodo to add a new task
addTodo();
}
}
});


// Hide edit cancel action button on page load
const cancelEditBtn = document.querySelector('.js-cancel-button');
cancelEditBtn.style.display = 'none';
Expand Down

0 comments on commit 65d2810

Please sign in to comment.