I'm not talking about boolean attributes, attributes like class
if you don't want to add an empty class attribute if there's no CSS class.
html`<span class=${hasClass ? 'my-class' : ''}></span>`
There is an ifDefined
directive that does what you want. If the value is undefined
the attribute won't be rendered.
import {ifDefined} from 'lit-html/directives/if-defined';
html`<span class=${ifDefined(hasClass ? 'my-class' : undefined)}></span>`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With