bits-ui 1.4.7 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,8 +16,9 @@ class CheckboxGroupState {
16
16
  if (!checkboxValue)
17
17
  return;
18
18
  if (!this.opts.value.current.includes(checkboxValue)) {
19
- this.opts.value.current.push(checkboxValue);
20
- this.opts.onValueChange.current(this.opts.value.current);
19
+ const newValue = [...$state.snapshot(this.opts.value.current), checkboxValue];
20
+ this.opts.value.current = newValue;
21
+ this.opts.onValueChange.current(newValue);
21
22
  }
22
23
  }
23
24
  removeValue(checkboxValue) {
@@ -26,8 +27,9 @@ class CheckboxGroupState {
26
27
  const index = this.opts.value.current.indexOf(checkboxValue);
27
28
  if (index === -1)
28
29
  return;
29
- this.opts.value.current.splice(index, 1);
30
- this.opts.onValueChange.current(this.opts.value.current);
30
+ const newValue = this.opts.value.current.filter((v) => v !== checkboxValue);
31
+ this.opts.value.current = newValue;
32
+ this.opts.onValueChange.current(newValue);
31
33
  }
32
34
  props = $derived.by(() => ({
33
35
  id: this.opts.id.current,
@@ -28,9 +28,9 @@
28
28
  required: box.with(() => Boolean(required)),
29
29
  name: box.with(() => name),
30
30
  value: box.with(
31
- () => value,
31
+ () => $state.snapshot(value),
32
32
  (v) => {
33
- value = v;
33
+ value = $state.snapshot(v);
34
34
  onValueChange(v);
35
35
  }
36
36
  ),
@@ -4,6 +4,7 @@
4
4
  import { CheckboxGroupContext, useCheckboxRoot } from "../checkbox.svelte.js";
5
5
  import CheckboxInput from "./checkbox-input.svelte";
6
6
  import { useId } from "../../../internal/use-id.js";
7
+ import { watch } from "runed";
7
8
 
8
9
  let {
9
10
  checked = $bindable(false),
@@ -32,6 +33,19 @@
32
33
  }
33
34
  }
34
35
 
36
+ watch.pre(
37
+ () => value,
38
+ () => {
39
+ if (group && value) {
40
+ if (group.opts.value.current.includes(value)) {
41
+ checked = true;
42
+ } else {
43
+ checked = false;
44
+ }
45
+ }
46
+ }
47
+ );
48
+
35
49
  const rootState = useCheckboxRoot(
36
50
  {
37
51
  checked: box.with(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",