mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
Enhance Checkbox to use bind:group (#947)
* Enhance Checkbox to use bind:group * Use custom logic * Move multiple checkboxes above skeleton * Incorprate PR feedback * Any instead of string
This commit is contained in:
parent
8443b2d7c1
commit
f0cf4e7ba5
7 changed files with 58 additions and 7 deletions
|
@ -3,12 +3,21 @@
|
|||
* @event {boolean} check
|
||||
*/
|
||||
|
||||
/** Specify the value of the checkbox */
|
||||
/**
|
||||
* Specify the value of the checkbox
|
||||
* @type {any}
|
||||
*/
|
||||
export let value = "";
|
||||
|
||||
/** Specify whether the checkbox is checked */
|
||||
export let checked = false;
|
||||
|
||||
/**
|
||||
* Specify the bound group
|
||||
* @type {any[]}
|
||||
*/
|
||||
export let group = [];
|
||||
|
||||
/** Specify whether the checkbox is indeterminate */
|
||||
export let indeterminate = false;
|
||||
|
||||
|
@ -73,7 +82,7 @@
|
|||
bind:this="{ref}"
|
||||
type="checkbox"
|
||||
value="{value}"
|
||||
checked="{checked}"
|
||||
checked="{checked || group.includes(value)}"
|
||||
disabled="{disabled}"
|
||||
id="{id}"
|
||||
indeterminate="{indeterminate}"
|
||||
|
@ -83,6 +92,9 @@
|
|||
on:change
|
||||
on:change="{() => {
|
||||
checked = !checked;
|
||||
group = group.includes(value)
|
||||
? group.filter((_value) => _value !== value)
|
||||
: [...group, value];
|
||||
}}"
|
||||
on:blur
|
||||
/>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue