Conditional boolean attributes
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 46
- Avg merge
- 10m
- Merged PRs (30d)
- 2
Description
Consider this lit-html template
html`<a href="${ifDefined(href)}"></a>`;
if href is undefined, the output will be:
<a></a>
Why is this important?
Consider
<script webc:for="script of scripts"
:defer="script.defer"
:async="script.async"
:src="url(script.src)"></script>
In this case, all scripts will be async and defer because those are boolean attributes whose presence indicates true.
If we wanted to use a template and ifs:
<template webc:nokeep webc:for="script of scripts">
<script webc:if="defer && async" defer async :src="url(script.src)"></script>
<script webc:elseif="defer" defer :src="url(script.src)"></script>
<script webc:elseif="async" async :src="url(script.src)"></script>
<script webc:else :src="url(script.src)"></script>
</template>
I guess that's ok? If you have lots of attrs, you have to keep track of a whole tree of if/then/else.
But what if null meant "remove this attribute"?:
<script webc:for="script of scripts"
:defer="script.defer ?? null"
:async="script.async ?? null"
:src="url(script.src)"></script>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named in the issue. Start by tracing the existing handling of bound attributes using the examples above; done when null removes boolean attributes while truthy values preserve their presence and existing non-boolean behavior remains covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100