Skip to content

Commit

Permalink
docs: add escape key closing to sidenav
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroedin committed Feb 26, 2024
1 parent 9b5d3ee commit 5f32105
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/assets/elements/uxdot-sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class UxdotSideNav extends LitElement {
this.#triggerElement = (this.getRootNode()).getElementById(this.trigger);
this.#triggerElement.addEventListener('click', this.#onTriggerClick.bind(this));
this.addEventListener('click', this.#onClick.bind(this));
this.addEventListener('keydown', this.#onKeydown.bind(this));
}

disconnectedCallback() {
Expand Down Expand Up @@ -153,6 +154,20 @@ class UxdotSideNav extends LitElement {
return;
}
}

#onKeydown(event) {
switch (event.key) {
case 'Escape': {
if (!this.open) {
return;
}
this.toggle();
break;
}
default:
break;
}
}
}

/* ****************** */
Expand Down

0 comments on commit 5f32105

Please sign in to comment.