Skip to content

Commit

Permalink
Merge pull request #954 from dnum-mi/fix/dsfr-tooltip-focus-and-escape
Browse files Browse the repository at this point in the history
fix: 🐛 affiche l’infobulle au focus et la cache avec ESC
  • Loading branch information
laruiss authored Oct 3, 2024
2 parents b1ad8bd + dff2afb commit bb4d8d4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/DsfrTooltip/DsfrTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,20 @@ const clickListener = (event: MouseEvent) => {
show.value = false
}
const onEscapeKey = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
show.value = false
}
}
onMounted(() => {
document.documentElement.addEventListener('click', clickListener)
document.documentElement.addEventListener('keydown', onEscapeKey)
})
onUnmounted(() => {
document.documentElement.removeEventListener('click', clickListener)
document.documentElement.removeEventListener('keydown', onEscapeKey)
})
const onMouseEnter = () => {
Expand Down Expand Up @@ -127,6 +135,8 @@ const onClick = () => {
@click.stop="onClick()"
@mouseenter="onMouseEnter()"
@mouseleave="onMouseLeave()"
@focus="onMouseEnter()"
@blur="onMouseLeave()"
>
<!-- @slot Slot par défaut pour le contenu de l’infobulle -->
<slot />
Expand Down

0 comments on commit bb4d8d4

Please sign in to comment.