Skip to content

Commit f6db640

Browse files
committed
Close menu when focus leaves
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent a620b9f commit f6db640

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

js/notifications-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/notifications-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/notifications-settings.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/notifications-settings.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/HeaderMenu.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
<div v-show="opened"
3838
:id="`header-menu-${id}`"
3939
class="header-menu__wrapper"
40-
role="menu">
40+
role="menu"
41+
@focusout="handleFocusOut">
4142
<div class="header-menu__content">
4243
<slot />
4344
</div>
@@ -157,6 +158,12 @@ export default {
157158
this.$emit('update:open', false)
158159
}
159160
},
161+
162+
handleFocusOut(event) {
163+
if (!event.currentTarget.contains(event.relatedTarget)) {
164+
this.closeMenu()
165+
}
166+
},
160167
},
161168
}
162169
</script>

src/NotificationsApp.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,16 @@ export default {
248248
249249
methods: {
250250
onOpen() {
251+
this.focusFirstFocusable()
251252
this.requestWebNotificationPermissions()
252253
},
254+
255+
focusFirstFocusable() {
256+
this.$nextTick(() => {
257+
this.$el.querySelector('.button-vue').focus()
258+
})
259+
},
260+
253261
handleNetworkOffline() {
254262
console.debug('Network is offline, slowing down pollingInterval to ' + this.pollIntervalBase * 10)
255263
this._setPollingInterval(this.pollIntervalBase * 10)
@@ -481,6 +489,12 @@ export default {
481489
</script>
482490
483491
<style scoped lang="scss">
492+
:deep(.button-vue) {
493+
&:focus {
494+
outline: 2px solid var(--color-main-text) !important;
495+
}
496+
}
497+
484498
.notifications-button__icon {
485499
filter: var(--background-image-invert-if-bright);
486500
}

0 commit comments

Comments
 (0)