svelte-select-5 6.0.1 → 6.0.3

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.
package/Select.svelte CHANGED
@@ -13,13 +13,15 @@
13
13
  // Props with $props() rune
14
14
  let {
15
15
  // Bindable props (two-way binding)
16
- justValue = $bindable(null),
17
- container = $bindable(undefined),
18
- input = $bindable(undefined),
16
+ // Note: Props that can be undefined don't have fallback values
17
+ // to allow bind:prop={undefined} (Svelte 5 requirement)
18
+ justValue = $bindable(),
19
+ container = $bindable(),
20
+ input = $bindable(),
19
21
  focused = $bindable(false),
20
- value = $bindable(null),
22
+ value = $bindable(),
21
23
  filterText = $bindable(''),
22
- items = $bindable(null),
24
+ items = $bindable(),
23
25
  loading = $bindable(false),
24
26
  listOpen = $bindable(false),
25
27
  hoverItemIndex = $bindable(0),
@@ -120,6 +122,7 @@
120
122
  let isScrolling = $state(false);
121
123
  let prefloat = $state(true);
122
124
  let _inputAttributes = $state({});
125
+ let prevJustValue = $state(undefined);
123
126
  let isScrollingTimer;
124
127
 
125
128
  // Floating UI config - using closure for listOffset to capture current value
@@ -717,6 +720,26 @@
717
720
  justValue = computeJustValue();
718
721
  });
719
722
 
723
+ // Handle external changes to justValue (allows setting value via justValue)
724
+ $effect(() => {
725
+ const computed = computeJustValue();
726
+ const isExternalChange = justValue !== prevJustValue &&
727
+ JSON.stringify(justValue) !== JSON.stringify(computed);
728
+
729
+ if (isExternalChange && items) {
730
+ if (multiple) {
731
+ value = justValue
732
+ ? items.filter(item => justValue.includes(item[itemId]))
733
+ : null;
734
+ } else {
735
+ value = justValue != null
736
+ ? items.find(item => item[itemId] === justValue) ?? null
737
+ : null;
738
+ }
739
+ }
740
+ prevJustValue = justValue;
741
+ });
742
+
720
743
  $effect(() => {
721
744
  if (!multiple && prev_value && !value) oninput?.(value);
722
745
  });
@@ -13,13 +13,15 @@
13
13
  // Props with $props() rune
14
14
  let {
15
15
  // Bindable props (two-way binding)
16
- justValue = $bindable(null),
17
- container = $bindable(undefined),
18
- input = $bindable(undefined),
16
+ // Note: Props that can be undefined don't have fallback values
17
+ // to allow bind:prop={undefined} (Svelte 5 requirement)
18
+ justValue = $bindable(),
19
+ container = $bindable(),
20
+ input = $bindable(),
19
21
  focused = $bindable(false),
20
- value = $bindable(null),
22
+ value = $bindable(),
21
23
  filterText = $bindable(''),
22
- items = $bindable(null),
24
+ items = $bindable(),
23
25
  loading = $bindable(false),
24
26
  listOpen = $bindable(false),
25
27
  hoverItemIndex = $bindable(0),
@@ -120,6 +122,7 @@
120
122
  let isScrolling = $state(false);
121
123
  let prefloat = $state(true);
122
124
  let _inputAttributes = $state({});
125
+ let prevJustValue = $state(undefined);
123
126
  let isScrollingTimer;
124
127
 
125
128
  // Floating UI config - using closure for listOffset to capture current value
@@ -717,6 +720,26 @@
717
720
  justValue = computeJustValue();
718
721
  });
719
722
 
723
+ // Handle external changes to justValue (allows setting value via justValue)
724
+ $effect(() => {
725
+ const computed = computeJustValue();
726
+ const isExternalChange = justValue !== prevJustValue &&
727
+ JSON.stringify(justValue) !== JSON.stringify(computed);
728
+
729
+ if (isExternalChange && items) {
730
+ if (multiple) {
731
+ value = justValue
732
+ ? items.filter(item => justValue.includes(item[itemId]))
733
+ : null;
734
+ } else {
735
+ value = justValue != null
736
+ ? items.find(item => item[itemId] === justValue) ?? null
737
+ : null;
738
+ }
739
+ }
740
+ prevJustValue = justValue;
741
+ });
742
+
720
743
  $effect(() => {
721
744
  if (!multiple && prev_value && !value) oninput?.(value);
722
745
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-select-5",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "description": "A <Select> component for Svelte 5 apps (fork of svelte-select)",
5
5
  "repository": "https://github.com/Dbone29/svelte-select-5.git",
6
6
  "author": "Robert Balfré <rob.balfre@gmail.com> (https://github.com/rob-balfre)",