Skip to content

Reflected attributes cause unexpected behaviorΒ #74

@JamesIves

Description

@JamesIves

Components which use reflect: true, when using the @property decorator or this.setAttribute result in unexpected behavior.

To reproduce this:

  1. Create a component that uses this pattern, for example use the following, and then do something like :host[is-open] {} in the CSS as a response to the attribute being present.
@property({type: Boolean, attribute: 'is-open', reflect: true})
public isOpen: boolean = false;
  1. Have the component manage its own state, for instance it should run this.isOpen = true and then this.isOpen = false at some stage in its lifecycle.
  2. When the first isOpen is called and set to true, it reflects the attribute into the URL bar to keep Storybook controls in sync.
  3. When the second occurance happens, the attribute remains present in the URL, and does not correctly remove the attribute from the component.

As a result component previews for some interactive elements do not work in Storybook. I've tried ignoring the option with addon-controls by extending argTypes and setting controls to false to no avail. I've also tried adding a JSDoc comment as @private to see if that somehow causes it to ignore that attribute name by removing it from the generated custom elements manifest, but alas, no luck. Seems the only solution for these cases in the meantime is to not use the template method here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions