Skip to content

Commit

Permalink
[#801] Made it possible to close menu with escape key
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Jan 5, 2023
1 parent d1ff0f0 commit 0f94d22
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/open_inwoner/js/components/dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class Dropdown {
this.button = node.querySelector('.button')
this.button.addEventListener('click', this.toggleOpen.bind(this))
document.addEventListener('click', this.doClosing.bind(this), false)
document.addEventListener('keydown', this.doClosing.bind(this), false)
}

toggleOpen(event) {
Expand All @@ -17,7 +18,12 @@ export class Dropdown {
}

doClosing(event) {
this.node.classList.remove('dropdown--open')
if (
event.type === 'click' ||
(event.type === 'keydown' && event.key === 'Escape')
) {
this.node.classList.remove('dropdown--open')
}
}
}

Expand Down

0 comments on commit 0f94d22

Please sign in to comment.