Skip to content

Commit

Permalink
Fix actions dropdown focus timing
Browse files Browse the repository at this point in the history
Because "@after-show" is still happening too early due to v-tooltip's
use of "requestAnimationFrame" we can't rely on its events to tell us
when the popover is actually visible.

This workaround introduces an additional Popover event "after-show" and
"after-hide" that are based on monitoring the inner "isOpen" property
which is the one toggling the CSS visibility.

The Actions popover logic now uses "after-show" to reliably apply the
focus on the first action element.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
  • Loading branch information
PVince81 committed Mar 12, 2021
1 parent caa5188 commit a3774bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/components/Actions/Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default {
:boundaries-element="boundariesElement"
:container="container"
@show="openMenu"
@apply-show="onOpen"
@after-show="onOpen"
@hide="closeMenu">
<!-- Menu open/close trigger button -->
<button slot="trigger"
Expand Down Expand Up @@ -502,8 +502,6 @@ export default {
* Event emitted when the popover menu is closed
*/
this.$emit('open')
this.onOpen(e)
},
closeMenu(e) {
if (!this.opened) {
Expand Down
19 changes: 19 additions & 0 deletions src/components/Popover/Popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ With a `<button>` as a trigger:

<template>
<VPopover
ref="popover"
v-bind="$attrs"
popover-base-class="popover"
popover-wrapper-class="popover__wrapper"
Expand All @@ -74,6 +75,24 @@ export default {
components: {
VPopover,
},
mounted() {
this.$watch(
() => {
// required because v-tooltip doesn't provide events
// and @show is too early
// see https://github.com/Akryum/v-tooltip/issues/661
return this.$refs.popover.isOpen
},
(val) => {
if (val) {
this.$emit('after-show')
} else {
this.$emit('after-hide')
}
}
)
},
}
</script>

Expand Down

0 comments on commit a3774bc

Please sign in to comment.