Is there a simpler way to write the following checkbox component:
<script>
export let disabled = false;
</script>
{#if disabled}
<label class="checkbox" disabled>
<input type="checkbox" {disabled} />
<slot></slot>
</label>
{:else}
<label class="checkbox">
<input type="checkbox" {disabled} />
<slot></slot>
</label>
{/if}
Having <label disabled="false"> is not acceptable because Bulma have a CSS class .checkbox[disabled].
disabled || null (or disabled || undefined) will do the trick:
<label class="checkbox" disabled={disabled || null}>
<input type="checkbox" {disabled} />
<slot></slot>
</label>
From the docs:
... [A]ttributes are included unless their value is nullish (
nullorundefined).<input required={false} placeholder="This input field is not required"> <div title={null}>This div has no title attribute</div>
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