Skip to content

Commit bff6687

Browse files
authored
Show tooltip on keyboard focus (#20)
1 parent f84c835 commit bff6687

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/Tooltip.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const visible = ref(false)
5858
const timeout = useTimeoutPool()
5959
const id = getTooltipId()
6060
61-
function handleTargetMouseEnter() {
61+
function handleTargetInteractionStart() {
6262
timeout.cancel('_')
6363
6464
if (openTooltips.size > 0) {
@@ -73,16 +73,25 @@ function handleTargetMouseEnter() {
7373
}
7474
}
7575
76-
function handleTargetMouseLeave() {
76+
function handleTargetInteractionEnd() {
7777
timeout.cancel('_')
7878
visible.value = false
7979
timeout.set('_', () => {
8080
openTooltips.delete(id)
8181
}, /** leave animation duration */200)
8282
}
8383
84-
useEventListener(() => props.target, 'mouseenter', handleTargetMouseEnter)
85-
useEventListener(() => props.target, 'mouseleave', handleTargetMouseLeave)
84+
const targetGetter = () => props.target
85+
86+
useEventListener(targetGetter, 'mouseenter', handleTargetInteractionStart)
87+
useEventListener(targetGetter, 'mouseleave', handleTargetInteractionEnd)
88+
useEventListener(targetGetter, 'blur', handleTargetInteractionEnd)
89+
useEventListener(targetGetter, 'focus', (e) => {
90+
if (!(e.target instanceof HTMLElement) || !e.target.hasAttribute('data-focus-visible-added'))
91+
return
92+
93+
handleTargetInteractionStart()
94+
})
8695
8796
onScopeDispose(() => {
8897
openTooltips.delete(id)

0 commit comments

Comments
 (0)