Open Rumyra opened 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:
HTMLElement.beforetoggle
and toggle
- update to mention that beforetoggle
is cancellable. This is importanttoggle
event AFAIK - not a custom one on HTMLDetailsElement
Just to clarify here, for better visibility outside of bugzilla:
I think this adds
beforetoggle
andtoggle
to<dialog>
element matching the popover behaviour.
Correct.
I also think the
<details>
is a little different than documented (it just does thetoggle
).
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.
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.
@keithamus Do you happen to know if/when these events are expected for Chromium and Safari?
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.
Some potentially useful examples:
beforetoggle
where newState
is open
, call replaceState()
with an anchor of the dialog name, and add the equivalent opening code for onload
.<dialog>
on beforetoggle
/toggle
which can help with animations.beforetoggle
find all popover=manual
and call .hidePopover()
on them.toggle
where newState
is closed
, call dialog.querySelector('form').reset()
or other state-resetting functionality to ensure when the dialog is re-opened it is set to its initial state.Thanks @keithamus .
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.
I did take those suggestions and make them as examples in the beforetoggle introduction
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.
Acceptance criteria
For folks helping with Firefox related documentation
dev-doc-complete
Related Gecko bugs
https://bugzilla.mozilla.org/show_bug.cgi?id=1876762
Other