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

Documentation on expressions should be updated #1361

Closed
fireflysemantics opened this issue Aug 14, 2024 · 2 comments
Closed

Documentation on expressions should be updated #1361

fireflysemantics opened this issue Aug 14, 2024 · 2 comments

Comments

@fireflysemantics
Copy link

In the documentation on expressions it says the following:

You might also want to remove the attribute if the value is not truthy so that values of false or empty string '' remove the attribute

Empty string '' is truthy. So an empty string will leave the attribute in place.

This is the demo snippet in the documentation.

html`<button aria-label="${this.ariaLabel || nothing}"></button>`

This will leave the attribute in place if ariaLabel=''.

https://stackblitz.com/edit/vitejs-vite-d25wmw?file=package.json

@augustjk
Copy link
Member

Empty string is falsy and as such it the code snippet correctly falls back to nothing when using ||, therefore removing the attribute.
See this playground example. If you inspect the <p> element, foo attribute does not exist, but bar does.

I also do not see any attribute on the <button> element in the provided stackblitz example either.

@fireflysemantics
Copy link
Author

@augustjk good catch .... I got my wires crossed ... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants