KABBOUCHI / vue-tippy

VueJS Tooltip powered by Tippy.js
https://vue-tippy.netlify.app
MIT License
731 stars 89 forks source link

WCAG 1.4.13 Issue: Tooltips not hoverable or dismissible #296

Closed tommed closed 1 year ago

tommed commented 1 year ago

According to WCAG, all tooltips should be dismissible by pressing the escape character on your keyboard.

I thought may be we could do something custom by hooking into the keyboard event and keeping a reference of the tooltip being shown, but thought given the requirement in WCAG this is something that should be implemented within this library.

Is there a way to make all tooltips dismissible on escape please?

KABBOUCHI commented 1 year ago

Is there a way to make all tooltips dismissible on escape please?

[...document.querySelectorAll("[data-tippy-root]")].forEach(el => el._tippy?.hide())
tommed commented 1 year ago

Perfect, that worked a treat.

// WCAG: 1.4.13 Issue 019: Tooltips not hover-able or dismissible
// hook into keypress and hide all tooltips on esc press
function tippyOnKeyPress(e) {
  if(e.which == 27){
    ([ ...document.querySelectorAll("[data-tippy-root]") ]).forEach(el => el._tippy?.hide())
  }
}

router.afterEach(() => {
  // tooltip dismiss (needed for wcag compliance)
  document.removeEventListener('keydown', tippyOnKeyPress)
  document.addEventListener('keydown', tippyOnKeyPress)
})