mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
improve formdata event detection
This commit is contained in:
@@ -14,6 +14,7 @@ _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
|
||||
|
||||
@@ -69,26 +69,8 @@ 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 || supportsFormDataEvent()) {
|
||||
if (!window.FormData || !('FormDataEvent' in window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user