revert formdata event detection

This commit is contained in:
Cory LaViska
2022-06-10 17:22:34 -04:00
parent c850a7eae1
commit ca876b291a
2 changed files with 19 additions and 2 deletions

View File

@@ -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

View File

@@ -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;
}