Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug on different property vs attribute names via Lit property decorator #86

Open
scottnath opened this issue Dec 26, 2024 · 4 comments
Open

Comments

@scottnath
Copy link

Hi @break-stuff ,

When creating a different attribute name vs a property name using Lit's @property() decorator, the property is picked up by Storybook docs, but the attribute is not.

Minimal reproduction (minor changes to lit-starter-kit)
break-stuff/lit-starter-kit@main...scottnath:lit-starter-kit:main

I adjusted variation in the lit-starter-kit to be:

  @property({ type: String, attribute: 'data-variation' })
  variation?: 'default' | 'primary' | 'hollow' | 'transparent';

meaning the attribute is data-variation but the property is just variation.

I added two stories, and the first one AttrVsProp shows the attribute data-variation as empty and this.variation is not configured. In the second, PropVsAttr the attribute data-variation is populated correctly and this.variation has the correct content

export const AttrVsProp: Story = {
  args: {
    'default-slot': 'My Button',
    variation: 'primary'
  },
};

export const PropVsAttr: Story = {
  args: {
    'default-slot': 'My Button',
    'data-variation': 'primary'
  },
};

Is there a way to configure either cem-creation or the break-stuff tools to have this work as expected (both attribute and property properly populate the component and storybook controls when used) or is this a bug?

thank you for any help,
Scott

@break-stuff
Copy link
Owner

Would you expect that all attributes be displayed in the attributes section and all of the corresponding properties be displayed separately in the properties section? That would bloat up the controls section and may make it confusing for users.

@scottnath
Copy link
Author

scottnath commented Dec 27, 2024

No, what helpers shows is great (shows only attributes in storybook controls, not properties), I would just want data-variation to be populated in the controls even if the user used variation - is that possible?

@break-stuff
Copy link
Owner

Ah, if you set reflect: true in the @property decorator, doest that give you the experience you're looking for?

@scottnath
Copy link
Author

added reflect, did not change docs in storybook
break-stuff/lit-starter-kit@main...scottnath:lit-starter-kit:main

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

No branches or pull requests

2 participants