Skip to content

Commit

Permalink
feat: 로고 클릭할 경우 searchBox value 초기화 해주는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Hain-tain committed Mar 21, 2024
1 parent 57f874a commit 9e9c476
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/MovieHeader/MovieHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ class MovieHeader {
const $h1 = createElement({
tagName: "h1",
children: [$logo],
addEventListener: { click: logoClickHandler },
addEventListener: {
click: () => {
searchBox.clear();
logoClickHandler();
},
},
});
const $searchBox = new MovieSearchBox({
const searchBox = new MovieSearchBox({
searchBoxSubmitHandler,
}).$element;
});

return generateHeader({ children: [$h1, $searchBox] });
return generateHeader({ children: [$h1, searchBox.$element] });
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/components/MovieHeader/MovieSearchBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class MovieSearchBox {
});
}

clear() {
if (this.$element instanceof HTMLFormElement) {
this.$element.reset();
}
}

private searchByQuery(e: Event) {
e.preventDefault();

Expand Down

0 comments on commit 9e9c476

Please sign in to comment.