Skip to content

Instantly share code, notes, and snippets.

@simenbrekken-visma
Created January 23, 2024 11:35
Show Gist options
  • Save simenbrekken-visma/0f5385d8b21429ae84c2c11f75620e2a to your computer and use it in GitHub Desktop.
Save simenbrekken-visma/0f5385d8b21429ae84c2c11f75620e2a to your computer and use it in GitHub Desktop.
/**
* Redispatch event with composed flag to propagate it through the shadow DOM.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
*/
function redispatchComposedEvent(event: Event) {
event.stopPropagation();
const composedEvent = new Event(event.type, {
bubbles: event.bubbles,
cancelable: event.cancelable,
composed: true,
});
event.target.dispatchEvent(composedEvent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment