mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-21 12:49:20 +00:00
docs(checkbox): add reactive example for bind:checked
Also distinguish it from the bind:group example
This commit is contained in:
parent
9e915cf90a
commit
63ba0038c3
2 changed files with 28 additions and 2 deletions
|
@ -23,9 +23,21 @@
|
|||
|
||||
<Checkbox labelText="Label text" disabled />
|
||||
|
||||
### Multiple
|
||||
### Reactive example (bind:checked)
|
||||
|
||||
Bind a selection [group](https://svelte.dev/tutorial/group-inputs) to multiple checkboxes.
|
||||
The `checked` prop supports two-way binding.
|
||||
|
||||
<FileSource src="/framed/Checkbox/CheckboxReactive" />
|
||||
|
||||
### Reactive example (bind:group)
|
||||
|
||||
An alternative to `checked` is binding an array of values using `group`. This API in inspired by Svelte [group inputs]([group](https://svelte.dev/tutorial/group-inputs)).
|
||||
|
||||
<InlineNotification svx-ignore title="Note:" kind="info" hideCloseButton>
|
||||
<div class="body-short-01">
|
||||
If using <strong>bind:group</strong>, <strong>bind:checked</strong> will only support one-way binding.
|
||||
</div>
|
||||
</InlineNotification>
|
||||
|
||||
<FileSource src="/framed/Checkbox/MultipleCheckboxes" />
|
||||
|
||||
|
|
14
docs/src/pages/framed/Checkbox/CheckboxReactive.svelte
Normal file
14
docs/src/pages/framed/Checkbox/CheckboxReactive.svelte
Normal file
|
@ -0,0 +1,14 @@
|
|||
<script>
|
||||
import { Checkbox, Button } from "carbon-components-svelte";
|
||||
|
||||
let checked = false;
|
||||
</script>
|
||||
|
||||
<Checkbox labelText="Label text" bind:checked />
|
||||
|
||||
<div style="margin: var(--cds-layout-01) 0">
|
||||
<Button on:click="{() => (checked = !checked)}">Toggle</Button>
|
||||
</div>
|
||||
|
||||
<strong>checked:</strong>
|
||||
{checked}
|
Loading…
Add table
Add a link
Reference in a new issue