mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
parent
e37b632fef
commit
048ebc7b81
4 changed files with 13 additions and 9 deletions
|
@ -16,7 +16,7 @@
|
|||
* Specify the bound group
|
||||
* @type {any[]}
|
||||
*/
|
||||
export let group = [];
|
||||
export let group = undefined;
|
||||
|
||||
/** Specify whether the checkbox is indeterminate */
|
||||
export let indeterminate = false;
|
||||
|
@ -59,6 +59,8 @@
|
|||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
$: useGroup = Array.isArray(group);
|
||||
$: checked = useGroup ? group.includes(value) : checked;
|
||||
$: dispatch("check", checked);
|
||||
</script>
|
||||
|
||||
|
@ -85,7 +87,7 @@
|
|||
bind:this="{ref}"
|
||||
type="checkbox"
|
||||
value="{value}"
|
||||
checked="{checked || group.includes(value)}"
|
||||
checked="{checked}"
|
||||
disabled="{disabled}"
|
||||
id="{id}"
|
||||
indeterminate="{indeterminate}"
|
||||
|
@ -94,10 +96,13 @@
|
|||
readonly="{readonly}"
|
||||
class:bx--checkbox="{true}"
|
||||
on:change="{() => {
|
||||
checked = !checked;
|
||||
group = group.includes(value)
|
||||
? group.filter((_value) => _value !== value)
|
||||
: [...group, value];
|
||||
if (useGroup) {
|
||||
group = group.includes(value)
|
||||
? group.filter((_value) => _value !== value)
|
||||
: [...group, value];
|
||||
} else {
|
||||
checked = !checked;
|
||||
}
|
||||
}}"
|
||||
on:change
|
||||
on:blur
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue