Skip to content

Commit

Permalink
revert formdata event detection
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Jun 10, 2022
1 parent c850a7e commit ca876b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion docs/resources/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ _During the beta period, these restrictions may be relaxed in the event of a mis
- Improved RTL styles for `<sl-button-group>` [#783](https://github.com/shoelace-style/shoelace/issues/783)
- Improved RTL styles for the toast stack [#785](https://github.com/shoelace-style/shoelace/issues/785)
- Improved typings for translations and localized terms
- Improved the `FormData` event polyfill to use simpler detection logic
- Upgraded @shoelace-style/localize to 3.0

## 2.0.0-beta.75
Expand Down
20 changes: 19 additions & 1 deletion src/internal/formdata-event-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,26 @@ class FormDataPolyfill extends FormData {
}
}

function supportsFormDataEvent() {
const form = document.createElement('form');
let isSupported = false;

document.body.append(form);

form.addEventListener('submit', event => {
new FormData(event.target as HTMLFormElement);
event.preventDefault();
});

form.addEventListener('formdata', () => (isSupported = true));
form.dispatchEvent(new Event('submit', { cancelable: true }));
form.remove();

return isSupported;
}

function polyfillFormData() {
if (!window.FormData || !('FormDataEvent' in window)) {
if (!window.FormData || supportsFormDataEvent()) {
return;
}

Expand Down

0 comments on commit ca876b2

Please sign in to comment.