mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
parent
e37b632fef
commit
048ebc7b81
4 changed files with 13 additions and 9 deletions
|
@ -462,7 +462,7 @@ None.
|
|||
| Prop name | Kind | Reactive | Type | Default value | Description |
|
||||
| :------------ | :--------------- | :------- | :---------------------------------------- | ------------------------------------------------ | ------------------------------------------------- |
|
||||
| ref | <code>let</code> | Yes | <code>null | HTMLInputElement</code> | <code>null</code> | Obtain a reference to the input HTML element |
|
||||
| group | <code>let</code> | Yes | <code>any[]</code> | <code>[]</code> | Specify the bound group |
|
||||
| group | <code>let</code> | Yes | <code>any[]</code> | <code>undefined</code> | Specify the bound group |
|
||||
| checked | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Specify whether the checkbox is checked |
|
||||
| value | <code>let</code> | No | <code>any</code> | <code>""</code> | Specify the value of the checkbox |
|
||||
| indeterminate | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Specify whether the checkbox is indeterminate |
|
||||
|
|
|
@ -735,7 +735,6 @@
|
|||
"kind": "let",
|
||||
"description": "Specify the bound group",
|
||||
"type": "any[]",
|
||||
"value": "[]",
|
||||
"isFunction": false,
|
||||
"isFunctionDeclaration": false,
|
||||
"constant": false,
|
||||
|
|
|
@ -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
|
||||
|
|
2
types/Checkbox/Checkbox.svelte.d.ts
vendored
2
types/Checkbox/Checkbox.svelte.d.ts
vendored
|
@ -16,7 +16,7 @@ export interface CheckboxProps {
|
|||
|
||||
/**
|
||||
* Specify the bound group
|
||||
* @default []
|
||||
* @default undefined
|
||||
*/
|
||||
group?: any[];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue