Skip to content

Commit 9ad3676

Browse files
committed
feat(addNewProject): add input focus and submit using Enter key
1 parent b07f924 commit 9ad3676

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/scripts/Modules/UI.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export default class UI {
1212
//adding global event listeners
1313
this.newProjectPopupAddBtn.addEventListener('click', (event) => this.handleAddNewProject(event));
1414
this.newProjectPopupCancelBtn.addEventListener('click', ()=> this.newProjectPopup.classList.remove("active"));
15+
this.newProjectNameInput.addEventListener('keydown', (event) => {
16+
if (event.key === 'Enter') {
17+
this.handleAddNewProject(event);
18+
}
19+
});
1520
}
1621

1722
loadHomepage() {
@@ -68,10 +73,11 @@ export default class UI {
6873
openAddProjectPopup(event) {
6974
this.newProjectPopup.classList.add("active");
7075
this.newProjectNameInput.value = ""; // Clear the input field
76+
this.newProjectNameInput.focus();
7177
}
7278

7379
handleAddNewProject(event) {
74-
const newProjectName = this.newProjectNameInput.value;
80+
const newProjectName = this.newProjectNameInput.value.trim();
7581
const existingProjects = this.app.listProjects();
7682
if(newProjectName && !existingProjects.includes(newProjectName)){
7783
this.app.addProject(newProjectName);

0 commit comments

Comments
 (0)