You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have create a popover menu component and would like to set the focus on the first element inside the popover right after it has appeared.
Problem
To be able to call .focus() on the first element, we need to make sure that at this moment the Popover is mounted in the DOM and it has the class .open set, as it has to be actually visible.
This is currently not possible to detect reliably as there is no event triggered at the right moment.
In our current implementation we had used $nextTick() but since Popover uses requestAnimationFrame, there is no guarantee how many milliseconds must elapse before the open class gets set here: https://github.com/Akryum/v-tooltip/blob/master/src/components/Popover.vue#L360
To test the problem have a component listen to then @open event of the Popover, and use the following handler:
The messages in-between is where I tried to re-try the focus after a delay after noticing that the focus was not actually set.
As you can see the $nextTick did not get access to the DOM element and the "open" class only starts to appear after 50ms or so.
Instead of having to add arbitrary delays, it would be nice to trigger the "show" event only once the popover is actually visible.
Or, if there are concerns with backwards compatibility, emit a new event "afterShow" there.
This way in our use case we could simply listen to that event and apply the focus there.
The text was updated successfully, but these errors were encountered:
@PVince81 Setting no-auto-focus and @apply-show="$refs.input.focus()" fixes the issue for me. The lib seems to reset the focus somehow and no-auto-focus disables this.
Use case
We have create a popover menu component and would like to set the focus on the first element inside the popover right after it has appeared.
Problem
To be able to call
.focus()
on the first element, we need to make sure that at this moment the Popover is mounted in the DOM and it has the class.open
set, as it has to be actually visible.This is currently not possible to detect reliably as there is no event triggered at the right moment.
In our current implementation we had used
$nextTick()
but since Popover usesrequestAnimationFrame
, there is no guarantee how many milliseconds must elapse before theopen
class gets set here: https://github.com/Akryum/v-tooltip/blob/master/src/components/Popover.vue#L360To test the problem have a component listen to then
@open
event of the Popover, and use the following handler:You can see my result here:

The messages in-between is where I tried to re-try the focus after a delay after noticing that the focus was not actually set.
As you can see the
$nextTick
did not get access to the DOM element and the "open" class only starts to appear after 50ms or so.Note: this only happens the first time the popover opens. The second time it will directly set
this.isOpen=true
here https://github.com/Akryum/v-tooltip/blob/master/src/components/Popover.vue#L343Solution
Instead of having to add arbitrary delays, it would be nice to trigger the "show" event only once the popover is actually visible.
Or, if there are concerns with backwards compatibility, emit a new event "afterShow" there.
This way in our use case we could simply listen to that event and apply the focus there.
The text was updated successfully, but these errors were encountered: