Skip to content

Unclear reason for difference between testing components with properties VS attributes #2117

Answered by bennypowers
venikx asked this question in Q&A
Discussion options

You must be logged in to vote

there's a few things to be aware of here:

  1. in lit-html templates, <wc-a readonly="${true}"> will evaluate to <wc-a readonly="true"> and <wc-a readonly="${false}"> will evaluate to <wc-a readonly="false"> this is likely not what you want. Probably you want the attribute to be present when true and absent when false. For that, use this template syntax:
html`
  <wc-a ?readonly="${bool}"></wc-a>
`; 

The ? prefix on the attribute name signals that its a boolean attribute.

  1. if you want it to be the case that setting the property also sets (or unsets) the attribute, use
@property({ type: Boolean, reflect: true }) disabled = false;

the reflect flag makes lit-element reflect property assignments…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@venikx
Comment options

Answer selected by venikx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants