Skip to content

Commit

Permalink
Record the previous element that holds focus before the close button …
Browse files Browse the repository at this point in the history
…is clicked and transfer focus to that element once the header is dismissed
  • Loading branch information
apurva-modi committed Mar 29, 2021
1 parent 385b6a6 commit a8c1e73
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kolibri/core/assets/src/views/CoreBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</KGridItem>
<KGridItem v-else class="button-grid-item">
<KButton
ref="close_button"
class="close-button"
:text="coreString('closeAction')"
appearance="flat-button"
Expand All @@ -57,9 +58,22 @@
bannerClosed: false,
};
},
created() {
document.addEventListener('focusin', this.focusChange);
},
beforeDestroy() {
document.removeEventListener('focusin', this.focusChange);
},
methods: {
toggleBanner() {
this.bannerClosed = !this.bannerClosed;
this.previouslyFocusedElement.focus();
},
focusChange(e) {
// We need the element prior to the close button
if (this.$refs.close_button && e.target != this.$refs.close_button.$el) {
this.previouslyFocusedElement = e.target;
}
},
},
$trs: {
Expand Down

0 comments on commit a8c1e73

Please sign in to comment.