Skip to content

Conversation

koddsson
Copy link
Contributor

Given the component and markup:

@controller
class MyController extends HTMLElement {
  @target foo!: HTMLElement

  connectedCallback() {
    console.log(this.foo)
  }
}
<my-controller>
  <div data-target="my-controller.foobar"></div>
  <div data-target="my-controller.foo"></div>
</my-controller>

the component will log <div data-action="my-controller.foobar"></div> once it's connected even though we obviously wanted the other target.

This is because we are using a attribute selector that just checks that the attribute value contains the given value. Since foobar contains foo and it appears first in the DOM we'll return that even thought the user wanted the other target.

This change removes the contains attribute selector and just matches the data attribute value exactly.

Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

@koddsson koddsson requested a review from a team as a code owner June 10, 2020 11:14
@koddsson koddsson merged commit 6574a28 into master Jun 10, 2020
@koddsson koddsson deleted the match-targets-exactly branch June 10, 2020 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants