mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
9.19k stars 22.48k forks source link

[WebAPI] Implement dialog toggleevents for dialog open/close #36536

Open Rumyra opened 1 week ago

Rumyra commented 1 week ago

Acceptance criteria

For folks helping with Firefox related documentation

Related Gecko bugs

https://bugzilla.mozilla.org/show_bug.cgi?id=1876762

Other

hamishwillee commented 1 week ago

I think this adds beforetoggle and toggle to <dialog> element matching the popover behaviour. The problem is the popover behaviour needs a bit of work - it doesn't mention the events in the docs. I also think the <details> is a little different than documented (it just does the toggle). I am confirming all of this in https://bugzilla.mozilla.org/show_bug.cgi?id=1876762#c14

Status:

keithamus commented 5 days ago

Just to clarify here, for better visibility outside of bugzilla:

I think this adds beforetoggle and toggle to <dialog> element matching the popover behaviour.

Correct.

I also think the <details> is a little different than documented (it just does the toggle).

This is correct also. All three will dispatch a toggle event using the ToggleEvent constructor, and have appropriate newState and oldState properties set - but only popover and (now) <dialog> elements will dispatch beforetoggle on show/hide. I will eventually get around to speccing/implementing beforetoggle for <details> but this is still TBD.

Also worth pointing out beforetoggle on show (or open if you prefer that terminology) will be cancelable. beforetoggle on close is not cancelable. The toggle event is not cancelable.

hamishwillee commented 3 days ago

Thank you @keithamus - much appreciated (one thing I don't like about bugzilla is that you can't add an "acknowledged" or "thanks" without adding clutter to the discussion).

I'm working on this in https://github.com/mdn/content/pull/36606. Its taking a little longer than expected because I want to write a useful example.

hamishwillee commented 3 days ago

@keithamus Do you happen to know if/when these events are expected for Chromium and Safari?

keithamus commented 3 days ago

Flagged in Chrome 131, will ship in 132 https://chromestatus.com/roadmap.

I have a PR for Safari here: https://github.com/WebKit/WebKit/pull/23332 but it needs revisiting. I'll probably get around to it this month, but I don't know what the timelines will look like for Safari.

keithamus commented 3 days ago

Some potentially useful examples:

hamishwillee commented 2 days ago

Thanks @keithamus .

  1. I'm not so ambitious in my examples - the main thing I have done is added simple live examples showing how they are called, such as this one: https://pr36606.content.dev.mdn.mozit.cloud/en-US/docs/Web/API/HTMLDialogElement#opening_a_modal_dialog It would be good to try some of these, but not in this round.

  2. I did take those suggestions and make them as examples in the beforetoggle introduction

  3. Most of the work has been making the events "not popover centric" and working on how to show them in the docs for the elements they are fired on - since they are inherited that makes them a bit invisible using our normal patterns.