Skip to content

Commit

Permalink
Create a private function for event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
jibees committed Sep 22, 2023
1 parent 2a98789 commit 458a031
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/webpacker/controllers/vertical_ellipsis_menu_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ export default class extends Controller {

connect() {
super.connect();
window.addEventListener("click", (e) => {
if (this.element.contains(e.target)) return;
this.#hide();
});
window.addEventListener("click", this.#hideIfClickedOutside);
}

toggle() {
this.contentTarget.classList.toggle("show");
}

#hideIfClickedOutside = (event) => {
if (this.element.contains(event.target)) {
return;
}
this.#hide();
};

#hide() {
this.contentTarget.classList.remove("show");
}
Expand Down

0 comments on commit 458a031

Please sign in to comment.