Skip to content

Can bind:group for checkboxes be enhanced to accumulate bits? #14672

@webJose

Description

@webJose

Describe the problem

I like bitmasked enums. They consume very little RAM and working with them is super fast. I often build a bunch of checkboxes that represent an option (bitmasked value).

Describe the proposed solution

Just to be able to do bind:group using a number and bit values:

<script>  // State  let options = $state(0);   // Or directly as a prop is more desirable:  let {  options = $bindable(0),  } = $props(); </script> {#each [1, 2, 4, 8] as bit} <label> <input type="checkbox" value={bit} bind:group={options}>{bit} </label> {/each}

Svelte could detect my options variable is a number and therefore assume that all values in the bound checkboxes will be numbers that are added or removed using bitwise operators.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions