question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attributes with a hyphen do not reflect to LitElement property

See original GitHub issue

<a-thing with-property="Foo"></a-thing> with a property withProperty within class AThing extends LitElement does not reflect in the withProperty property.

Expected: withProperty has value "Foo"

Actual: withProperty is null

Glitch: Code, Demo

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
leonheesscommented, Nov 24, 2020

We elected not to support this automatic dash to camel case conversion from PolymerElement in LitElement because it was generally non-platform-y. Instead, lowercase attributes are automatically mapped to the correctly cased property which is what the platform itself does for properties like tabIndex.

This behavior can be customized by importing camelToDashCase from Polymer implementing

static attributeNameForProperty(property) {
  return camelToDashCase(property);
}

Can this decision still be challenged? This fundamentally limits the cross-compatibility with other frameworks like Vue.js which is kind of a bad thing for a web-component-focused framework, isn’t it?

3reactions
kenchriscommented, May 31, 2018

LitElement is about as vanilla as it gets, it is not trying to invent anything already present in the platform. It just adds a few things missing. There are even spec proposals like Template Instantiation, making lit-html even smaller - and making all of this just a tiny bit of convenience.

This is the future of Polymer as well, removing as much of the custom stuff as possible, and what turned out to not make sense, and just use the platform as much as possible, now that it is actually possible to do so.

Expect a lot of the “magic” from Polymer not to be present in LitElement, like reflection, computed values etc

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attributes with a hyphen do not reflect to LitElement property #29
with a property withProperty within class AThing extends LitElement does not reflect in the withProperty property.
Read more >
Properties - Lit.dev
LitElement manages your declared properties and their corresponding attributes. By default, LitElement will: Ensure that an element update is scheduled when ...
Read more >
Use of hyphenated property keys for element.style
I am familiar with the use of setting inline styles on elements using the elements style property. For style properties which are hyphenated...
Read more >
Lit-html-element NPM | npm.io
Mapping name is up to user, no automatical case-conversion happens; Default values of auto-reflected properties depend on presence of attributes.
Read more >
Turning up to Lit - DEV Community 👩‍💻👨‍💻
Tagged with litelement, polymer, webcomponents, javascript. ... This value will be reflected to an attribute everything-property ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found