Re: Best approach for meeting Success Criterion 1.4.13 Content on Hover or Focus via ESC key

Hi Detlev,

> I am just wondering what the most elegant way would be to implement closing via pressing ESC to close whatever popup menu or custom tool tip happens to be open on a page

A good resource for this type of thing is Heydon’s inclusive design components, e.g:
https://inclusive-components.design/tooltips-toggletips/


Includes:
// Remove toggletip on ESC
    toggletip.addEventListener('keydown', function(e) {
      if ((e.keyCode || e.which) === 27)
      liveRegion.innerHTML = '';
    });

The code within the if-statement will depend on how the pop-over was instantiated in the first place, but you get the idea.

I *think* that if you’ve registered that type of event on an element, even if you have more than one open, pressing esc will close every instance which has that event registered.

However, worth a test or discussion with a JS expert.

Cheers,

-Alastair

Received on Friday, 24 August 2018 10:10:41 UTC