Skip to content

Option to let createEventDispatcher pass through shadow DOM #3327

Closed as not planned
@threeid

Description

@threeid

Is your feature request related to a problem? Please describe.
createEventDispatcher can't not pass through shadow DOM boundaries.

As describe here, Link to lit-element doc, by default, a bubbling custom event fired inside shadow DOM will stop bubbling when it reaches the shadow root.

To make a custom event pass through shadow DOM boundaries, you must set both the composed and bubbles flags to true:

Currently, you have to hack like this:

  function handleInput(event) {
    this.dispatchEvent(new CustomEvent('change', {
      detail: event.target.value,
      bubbles: true,
      composed: true
    }))
  }

Describe the solution you'd like
Simple solution is like below:

createEventDispatcher({
  bubbles: true,
  composed: true,
  // other custom event options
})

Describe alternatives you've considered
Add another function like createCustomDispatcher to handle this case.

Or <svelte:host tag='custom-element' ref={that} attributes={['value', 'label']} />
which also allows you to reflect props to attributes for current custom component.

Or <svelte:options ref={that} />

that allow you to access to this keyword, with it you can use something like:
that.dispatchEvent or that.shadowRoot.querySelector()

How important is this feature to you?
I think this is important feature. Since you have no way but using hacky solution with this keyword.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions