Skip to content

Commit 6ecfbce

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

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,14 @@ export default {
248248
249249
methods: {
250250
onOpen() {
251+
this.focusFirstFocusable()
251252
this.requestWebNotificationPermissions()
252253
},
254+
255+
focusFirstFocusable() {
256+
this.$el.querySelector('.button-vue').focus()
257+
},
258+
253259
handleNetworkOffline() {
254260
console.debug('Network is offline, slowing down pollingInterval to ' + this.pollIntervalBase * 10)
255261
this._setPollingInterval(this.pollIntervalBase * 10)

0 commit comments

Comments
 (0)