WCF
WCF copied to clipboard
Fix inconsistent event handling in `woltlab-core-dialog.ts`
Previously some events that should have been cancelable were not.
The documentation says that close
, cancel
and validate
can be canceled. (the documentation also misses the cancelable backdrop
event)
I hope I tested all the event combinations / dialog options, but it’s possible I missed some edge cases. :worried:
Summary of the changes:
- if
validate
failed it unconditionally closed the dialog, not emitting theclose
event, now it does and checks the event state - if
validate
has no callbacks attached theclose
event gets emitted and if the dialog should not be closed theprimary
event is emitted manually - the
cancel
form button did not emit theclose
event, now it does and checks the event state - the
closeButton
unconditionally closed the dialog, not emitting theclose
event, now it does and checks the event state - the dialog’s native
cancel
event (emitted for example when a user presses theEscape
key or clicks on the backdrop) unconditionally closed the dialog while emitting a non-cancelablecancel
event. Now the customcancel
event is cancelable, like thecancel
form button event, and the event state is being checked. - the custom
close
event used to check whether the dialog should be closed by checking theevent.defaultPrevented
property was in fact not cancelable, now it is
Note: The backdrop
event is cancelable but does not have any effect in Firefox and Chromium. event.preventDefault()
and event.stopPropagation()
on the mousedown
event did not have any effect and the browser still emitted the cancel
event on the native dialog element.