WCF icon indicating copy to clipboard operation
WCF copied to clipboard

Fix inconsistent event handling in `woltlab-core-dialog.ts`

Open max-m opened this issue 1 year ago • 4 comments

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 the close event, now it does and checks the event state
  • if validate has no callbacks attached the close event gets emitted and if the dialog should not be closed the primary event is emitted manually
  • the cancel form button did not emit the close event, now it does and checks the event state
  • the closeButton unconditionally closed the dialog, not emitting the close event, now it does and checks the event state
  • the dialog’s native cancel event (emitted for example when a user presses the Escape key or clicks on the backdrop) unconditionally closed the dialog while emitting a non-cancelable cancel event. Now the custom cancel event is cancelable, like the cancel 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 the event.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.

max-m avatar Jan 20 '24 16:01 max-m