Skip to content

Commit c35e785

Browse files
authored
fix(Select): ensure data typeahead reacts with item changes (#1540)
1 parent 3e54e87 commit c35e785

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

.changeset/late-snakes-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bits-ui": patch
3+
---
4+
5+
fix(Select): ensure typeahead enabled state is reactive to item updates

packages/bits-ui/src/lib/bits/select/select.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class SelectTriggerState {
550550
if (!matchedItem) return;
551551
this.root.opts.value.current = matchedItem.value;
552552
},
553-
enabled: !this.root.isMulti && this.root.dataTypeaheadEnabled,
553+
enabled: () => !this.root.isMulti && this.root.dataTypeaheadEnabled,
554554
candidateValues: () => (this.root.isMulti ? [] : this.root.candidateLabels),
555555
getWindow: () => this.root.domContext.getWindow(),
556556
});

packages/bits-ui/src/lib/internal/use-data-typeahead.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type UseDataTypeaheadOpts = {
88
onMatch: (value: string) => void;
99
getCurrentItem: () => string;
1010
candidateValues: Getter<string[]>;
11-
enabled: boolean;
11+
enabled: Getter<boolean>;
1212
getWindow: () => Window & typeof globalThis;
1313
};
1414

@@ -21,7 +21,7 @@ export function useDataTypeahead(opts: UseDataTypeaheadOpts) {
2121
const candidateValues = $derived(opts.candidateValues());
2222

2323
function handleTypeaheadSearch(key: string) {
24-
if (!opts.enabled) return;
24+
if (!opts.enabled()) return;
2525
if (!candidateValues.length) return;
2626

2727
search.current = search.current + key;

0 commit comments

Comments
 (0)