mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-21 20:59:20 +00:00
docs(checkbox): demo two-way binding in bind:group example
This commit is contained in:
parent
63ba0038c3
commit
3a75244e34
1 changed files with 9 additions and 7 deletions
|
@ -1,15 +1,17 @@
|
||||||
<script>
|
<script>
|
||||||
import { Checkbox } from "carbon-components-svelte";
|
import { Checkbox, Button } from "carbon-components-svelte";
|
||||||
|
|
||||||
let options = ["Apple", "Banana", "Coconut"];
|
let values = ["Apple", "Banana", "Coconut"];
|
||||||
let selection = options.slice(0, 2);
|
let group = values.slice(0, 2);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each options as option}
|
{#each values as value}
|
||||||
<Checkbox bind:group="{selection}" labelText="{option}" value="{option}" />
|
<Checkbox bind:group labelText="{value}" value="{value}" />
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<div style="margin: var(--cds-layout-01) 0">
|
<div style="margin: var(--cds-layout-01) 0">
|
||||||
Selected options:
|
<Button on:click="{() => (group = ['Banana'])}">Set to ["Banana"]</Button>
|
||||||
<strong>{selection.join(", ")}</strong>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<strong>Selected:</strong>
|
||||||
|
{JSON.stringify(group)}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue