GoogleChrome / dialog-polyfill

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

Preventing default on the submit event of the enclosed form still closes the dialog #191

Closed runarberg closed 4 years ago

runarberg commented 4 years ago

How to reproduce

<dialog>
  <form id="my-dialog-form" method="dialog">
    <button value="close">Close</button>
  </form>
</dialog>
const dialogForm = document.getElementById('my-dialog-form');

dialogForm.addEventListener('submit', event => event.preventDefault());

Expected behavior

The dialog should not close. That is, the submit event should not trigger the close event for the <dialog>.

Actual behavior

The dialog closes. Note this does not happen if you add this listener in browsers that support native dialogs.