Svelte: `bind:group` does not work with nested components

Created on 25 Mar 2019  Â·  7Comments  Â·  Source: sveltejs/svelte

I'm trying to bind a store variable to group of checkboxes and it works till I move checkbox into a separate component, after that only one checkbox can be chosen at a time, here's an example from repl: https://gist.github.com/imbolc/e29205d6901d135c8c1bd8c3eec26d67

enhancement

Most helpful comment

I know, this is obvious, but still. For those, who run into the same problem: It would be sufficient to make separate component for the group of checkboxes, e.g. CheckboxGroup, which you can bind to a group <CheckboxGroup { checkboxes } bind:group/>.

See the example and learn some russian words :) https://svelte.dev/repl/faabda4cabd544bd858a8a8abd0095f5?version=3.12.1

All 7 comments

Yeah, this won't work as things currently stand — the group has to be within the component.

I suppose we could have a global Map of binding groups, though I'm not sure what the change notification looks like (for components other than the one with the element from which a change originated). This could be something to ponder post-3.0.

Is there a workaround for this in v3? It makes components that use a checkbox pretty difficult/confusing to use if you need to use groups.

https://svelte.dev/repl/1565708677134e418e256234984d90ef?version=3.12.1

Solution of this problem but without keep order of the selected items:

https://svelte.dev/repl/de117399559f4e7e9e14e2fc9ab243cc?version=3.12.1

I know, this is obvious, but still. For those, who run into the same problem: It would be sufficient to make separate component for the group of checkboxes, e.g. CheckboxGroup, which you can bind to a group <CheckboxGroup { checkboxes } bind:group/>.

See the example and learn some russian words :) https://svelte.dev/repl/faabda4cabd544bd858a8a8abd0095f5?version=3.12.1

This came up in the Discord today, what would be needed to make this work? Intuitively I feel like this should work out of the box.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bestguy picture bestguy  Â·  3Comments

robnagler picture robnagler  Â·  3Comments

ricardobeat picture ricardobeat  Â·  3Comments

matt3224 picture matt3224  Â·  3Comments

juniorsd picture juniorsd  Â·  3Comments