-
Notifications
You must be signed in to change notification settings - Fork 49
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
Support for conditional attributes? #164
Comments
It seems the feature already exists but is limited to the specific attributes. Lines 3 to 8 in bdd0efe
|
@saschanaz Although I like the implicit nullablitly, a better syntax for above could be:
It'll also avoid a rare but potential clash with having optional in attribute name. |
A way to do this today is using object spread: const optional = {}
if (nullableValue) optional['data-something-optional'] = nullableValue
html`
<div ${optional}></div>
` it's a bit verbose but I think I prefer it over introducing custom syntax. It is a bit strange that e; it can be made less verbose with a helper, function optional (attr, value) {
if (value) return { [attr]: value }
return {}
}
html`
<div ${optional('data-something', nullableValue)}></div>
` |
The
Seems less verbose than inserting conditional block everywhere 👍, but is |
it looks like it's missing from the docs, yes. it is definitely a tested and supported feature, though! |
|
Updates README.md with javascript object syntax described here: choojs#164 (comment)
Updates README.md with javascript object syntax described here: #164 (comment)
It can be useful if we get a declarative HTML way to conditionally define an attribute. Thoughts?
cc @sidvishnoi
The text was updated successfully, but these errors were encountered: