Skip to content

action modifier doesn't fire when inside shadow root #18303

Closed

Description

@knownasilya

<button {{action this.clicked}}> doesn't work while <button onclick={{action this.clicked}}> and <button {{on 'click' this.clicked}}> does.

Reproduction https://github.com/knownasilya/ember-shadow-dom/blob/master/tests/dummy/app/components/test-shadow/template.hbs#L13

Where the contents inside <ShadowDom>here</ShadowDom> are rendered in a shadow root like so:

{{#-in-element this.shadow}}
  {{yield}}
{{/-in-element}}

and the this.shadow is defined like so:

    let selector = this.selector;
    let element = document.querySelector(selector);
    let shadow = element.attachShadow({ mode: 'open' });

    this.set('shadow', shadow);

Activity

  1. rwjblue commented on Aug 23, 2019

    @rwjblue
    Member

    The way the {{action modifier works is by adding event handlers to the applications rootElement (most often body in non-tests), when the template will be rendered into a shadow root it is intentionally disconnected from the event bubbling that would eventually bubble to the document's body (or application rootElement if configured differently. This is a feature (of the shadow root system), not a bug. The reason onclick= works is because the event listener is attached directly to the element in question, and does not rely on any bubbling out of the shadow root.

    The "correct" solution here would be to avoid both forms of {{action and use {{on universally.

  2. rwjblue commented on Aug 23, 2019

    @rwjblue
    Member

    Since this isn't really a bug (and {{on works properly here already) I'm going to go ahead and close this, mostly as a "wontfix" because its basically impossible to fix...

  3. knownasilya commented on Aug 23, 2019

    @knownasilya
    ContributorAuthor

    @rwjblue thanks for the answer and quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions