Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esc key isn't closing HTML dialog elements #6914

Closed
shaunanoordin opened this issue Nov 3, 2023 · 2 comments
Closed

Esc key isn't closing HTML dialog elements #6914

shaunanoordin opened this issue Nov 3, 2023 · 2 comments

Comments

@shaunanoordin
Copy link
Member

shaunanoordin commented Nov 3, 2023

UX & Accessibility Overview

a.k.a. the Esc/Escape key isn't working for certain default web browser behaviour
Affects: anything that uses <dialog>; possibly any other standard HTML element/function that's supposed to react to the Esc key.

  • Expected: 'Esc' key should close any open <dialog>
  • Actual: 'Esc' is ignored.

The HTML dialog element can be used to open a popup or modal. This popup/modal should then close-able either by a custom close button that we program, or by pressing the 'Esc' key on the keyboard.

However, in PFE, this standard behaviour is disabled. In fact, it's possible that any standard browser behaviour that relies on the 'Esc' key is completely ignored.

Analysis

The problem was in our PJC's SugarClient, which has a copy of the primus library. Primus has a hack that specifically disables the 'Esc' key on the document level (document.onKeyDown)... which means the Esc key is disabled across the entirety of PFE.

Hack details
  //
  // Hack 2: If you press ESC in FireFox it will close all active connections.
  // Normally this makes sense, when your page is still loading. But versions
  // before FireFox 22 will close all connections including WebSocket connections
  // after page load. One way to prevent this is to do a `preventDefault()` and
  // cancel the operation before it bubbles up to the browsers default handler.
  // It needs to be added as `keydown` event, if it's added keyup it will not be
  // able to prevent the connection from being closed.
  //
  if (document.addEventListener) {
    document.addEventListener('keydown', function keydown(e) {
      if (e.keyCode !== 27 || !e.preventDefault) return;

      e.preventDefault();
    }, false);
  }

Dev Notes

Protip: if you encounter situations where pressing a key doesn't trigger the expected behaviour, use Chrome's Inspect element -> Event Listeners panel. This will list listeners for the element you want to get working, plus anything that bubbles up to parent elements. You can delete handlers one by one, and by process of elimination, you can figure out what's been blocking your key presses.

Status

Solved (for now) by #6912 and zooniverse/panoptes-javascript-client#223

Credit to @eatyourgreens for solving the problem by removing the hack from PJC's copy of Primus, and opening an issue on Primus itself: primus/primus#782

Ideally, these hacks should be removed from Primus - otherwise, whenever PJC syncs it copy with the latest version of Primus, we'll run into the same problem all over again.

@eatyourgreens
Copy link
Contributor

I've opened primus/primus#783 to remove that code from Primus itself. If that's accepted, then we shouldn't have to maintain our own edited copy of the client.

@eatyourgreens
Copy link
Contributor

I think this might also be in Cam’s handover notes for Sugar, but the latest version of the Primus client is available from https://notifications.zooniverse.org/primus.js.

Whenever Sugar is updated and deployed with a new version of Primus, you should download the new client code and commit it to the Panoptes client. Then release a new version of the Panoptes client. For Sugar to work properly, the Primus server and Primus client should both be on the same version of Primus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants