whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.02k stars 2.62k forks source link

popover light dismiss behavior is not specified for Esc key #9143

Closed asurkov closed 11 months ago

asurkov commented 1 year ago

The light dismiss paragraph mentions Esc key behavior used for auto popover light dismiss, but apparently it's not specified anywhere, see https://html.spec.whatwg.org/multipage/popover.html#popover-light-dismiss.

I suppose it should be simple as listen for keypress trusted event on a document and if Esc key was pressed and topmost auto popover is not null, then close it.

emilio commented 1 year ago

We should clearly define when this is supposed to happen, since it can run script... Curious, what does Chromium do @mfreed7 @josepharhar

josepharhar commented 1 year ago

This text currently specifies how it works:

user agents may provide a user interface that, upon activation, queues an element task on the user interaction task source given topmost auto popover to run the hide popover algorithm

I wrote it this way because I was copying the dialog element, which says the same thing:

user agents may provide a user interface that, upon activation, queues an element task on the user interaction task source given the dialog element to run these steps:

We should clearly define when this is supposed to happen, since it can run script

I totally agree. If CloseWatcher gets specced then it might be able to replace the existing text on its own and specify when this is supposed to happen, but I'm not opposed to improving the spec now without CloseWatcher.

Curious, what does Chromium do

If any node's default event handler sees a keydown event for the escape key and the event's target is the node, then chromium will close the active modal dialog if there is one and run popover light dismiss. I assume that default event handlers are well specified. Here is exactly where this occurs.

asurkov commented 1 year ago

This text currently specifies how it works:

user agents may provide a user interface that, upon activation, queues an element task on the user interaction task source given topmost auto popover to run the hide popover algorithm

I wrote it this way because I was copying the dialog element, which says the same thing:

If any node's default event handler sees a keydown event for the escape key and the event's target is the node, then chromium will close the active modal dialog if there is one and run popover light dismiss. I assume that default event handlers are well specified. Here is exactly where this occurs.

Would the spec benefit from providing the exact algorithm for Esc key handling similar to pointerup/down events algorithm? For example, it seems nothing indicates now that it has to be a keydown event.

josepharhar commented 1 year ago

Would the spec benefit from providing the exact algorithm for Esc key handling similar to pointerup/down events algorithm? For example, it seems nothing indicates now that it has to be a keydown event.

Yes, I believe it would benefit

emilio commented 1 year ago

For the record native popups in Gecko also use keydown, though we add a regular event listener to the document.

cc @smaug----

jakearchibald commented 1 year ago

I don't think it should queue a task. light dismiss open popovers doesn't queue a task.

nt1m commented 1 year ago

It would be nice to specify the precedence between active modal dialog, topmost auto popover and fullscreen element.

domenic commented 1 year ago

I think the right starting point for any spec here is https://wicg.github.io/close-watcher/#close-signals , which we could move into HTML at any time. (And get more review on it, as part of that move.)

Some notable choices made in that spec, which we could discuss:

domenic commented 1 year ago

We discussed this a bit in the triage meeting (https://github.com/whatwg/html/issues/9132). Points that came up:

josepharhar commented 1 year ago

if @mfreed7 or @josepharhar disagree from the perspective of popover="", please let us know.

This is fine. If we end up changing the chromium behavior, then I'll just do it behind a flag and may push back if it breaks any websites but I don't imagine thats likely.

mfreed7 commented 1 year ago
  • @emilio would prefer more mandatory interop / less user agent freedom than the Close Watcher spec provides, for example requiring keydown to be used for Esc key presses instead of allowing a choice of event. From the perspective of CloseWatcher, Chromium is fine with this; if @mfreed7 or @josepharhar disagree from the perspective of popover="", please let us know.

Yeah, I think this is ok too.

It would be nice to specify the precedence between active modal dialog, topmost auto popover and fullscreen element.

I just wanted to highlight this comment - I agree. I think the intention is that fullscreen always takes precedence, but there are open questions such as what happens if there are nested elements? For example, a fullscreen element contains an open popover. When Esc de-fullscreens the element, should it also close the popover?

I made a WPT for at least the basics of non-nested top layer elements, to verify which things close which things:

https://wpt.fyi/results/html/semantics/popovers/popover-top-layer-interactions.html?label=master&label=experimental&aligned

The Popover spec PR and that WPT basically just verify that everything closes popovers. But it doesn't clarify the other interactions, such as modal dialog and fullscreen.

mbrodesser-Igalia commented 1 year ago

I don't think it should queue a task. light dismiss open popovers doesn't queue a task.

@jakearchibald why shouldn't it queue a task? If that's agreed upon, it would be helpful to update the HTML spec (https://html.spec.whatwg.org/multipage/popover.html#popover-light-dismiss).

Even if above question was answered, the current spec wouldn't be precise enough to provide interoperable implementations.

domenic commented 1 year ago

I've put up #9462, which as part of porting over the close signal infrastructure, attempts to address this. I'd love reviews of that from folks. The relevant parts are at https://whatpr.org/html/9462/interaction.html#close-signal-steps .