I want to dynamically add an attribute to a Lit anchor element but I can't figure out how to do it. Specifically I want to add the download attribute.
Simple Attribute
This works:
return html`<a ?disabled=${this.disabled} download>Click here</a>`
This does not:
const downloadAttribute = this.download ? "download" : "";
return html`<a ?disabled=${this.disabled} ${downloadAttribute}>Click here</a>`
Attribute With Value
This works:
return html`<a ?disabled=${this.disabled} download=${fileName}>Click here</a>`
This does not:
const downloadAttribute = this.download ? `download=${filename}` : "";
return html`<a ?disabled=${this.disabled} ${downloadAttribute}>Click here</a>`
Any ideas as to how to get Lit to read downloadAttribute as an attribute and not as a string that it ignores?