GoogleChrome / dialog-polyfill

Polyfill for the HTML dialog element
BSD 3-Clause "New" or "Revised" License
2.45k stars 245 forks source link

The 'onclose' event handler is not implemented #174

Closed ghost closed 4 years ago

ghost commented 5 years ago

I've noticed that if you assign an event handler to the dialog's "onclose" property (or attribute), it is not called on dialog close. I think this should be mentioned in the "Limitations" section.

On the other hand, I've made a custom version of the polyfill that supports the "onclose" property (not the attribute). What I've done is to add the following code in the dialogPolyfillInfo.close method:

    close: function(opt_returnValue) {
      ...
      // Call the "onclose" event handler
      if (typeof this.dialog_.onclose == 'function') {
        this.dialog_.onclose({
          type: 'close',
          bubbles: false,
          cancelable: false,
          composed: false,
          defaultPrevented: false,
          isTrusted: true,
          eventPhase: Event.AT_TARGET,
          target: this.dialog_,
          currentTarget: this.dialog_,
          returnValue: this.dialog_.returnValue
        });
      }

      // Triggering "close" event for any attached listeners on the <dialog>.
      ...

Feel free to use this as the starting point for a proper implementation.

samthor commented 4 years ago

This was fixed in #184