Avoid bubbling events for sl-include (#897)

* Avoid bubbling events for sl-include

I ran into an issue where icons inside of an HTML include were dispatching `sl-load` events, which was causing my `sl-include` event handler to run multiple times. By adding these guards, we ensure only events immediately dispatched by the element itself will be handled.

* Use the correct event variable
pull/901/head
Jared White 2022-09-05 09:23:47 -07:00 zatwierdzone przez GitHub
rodzic 27868b56e8
commit ffd32e52ef
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 3 dodań i 1 usunięć

Wyświetl plik

@ -32,11 +32,13 @@ If the request fails, the `sl-error` event will be emitted. In this case, `event
<script> <script>
const include = document.querySelector('sl-include'); const include = document.querySelector('sl-include');
include.addEventListener('sl-load', () => { include.addEventListener('sl-load', event => {
if (event.eventPhase !== 2) return;
console.log('Success'); console.log('Success');
}); });
include.addEventListener('sl-error', event => { include.addEventListener('sl-error', event => {
if (event.eventPhase !== 2) return;
console.log('Error', event.detail.status); console.log('Error', event.detail.status);
}); });
</script> </script>