diff --git a/src/components/DsfrTooltip/DsfrTooltip.vue b/src/components/DsfrTooltip/DsfrTooltip.vue index 86b8fc48..ace7feb2 100644 --- a/src/components/DsfrTooltip/DsfrTooltip.vue +++ b/src/components/DsfrTooltip/DsfrTooltip.vue @@ -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 = () => { @@ -127,6 +135,8 @@ const onClick = () => { @click.stop="onClick()" @mouseenter="onMouseEnter()" @mouseleave="onMouseLeave()" + @focus="onMouseEnter()" + @blur="onMouseLeave()" >