Skip to content

Commit

Permalink
fix(combobox): only open when text exists and filtered items are pres…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
driskull committed Jun 17, 2024
1 parent 801152c commit 2ba7b5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ export namespace Components {
*/
"items": object[];
/**
* Specifies the fields to match against when filtering.
* Specifies the fields to match against when filtering. This will only apply when `value` is an object. If not set, all fields will be matched.
*/
"matchFields": string[];
/**
Expand Down Expand Up @@ -9622,7 +9622,7 @@ declare namespace LocalJSX {
*/
"items"?: object[];
/**
* Specifies the fields to match against when filtering.
* Specifies the fields to match against when filtering. This will only apply when `value` is an object. If not set, all fields will be matched.
*/
"matchFields"?: string[];
/**
Expand Down
11 changes: 8 additions & 3 deletions packages/calcite-components/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,7 @@ export class Combobox
inputHandler = (event: Event): void => {
const value = (event.target as HTMLInputElement).value;
this.text = value;
this.filterItems(value);
this.open = value.length > 0;
this.filterItems(value, true);
if (value) {
this.activeChipIndex = -1;
}
Expand All @@ -1071,7 +1070,7 @@ export class Combobox
isGroup(item) ? label === item.label : value === item.value && label === item.textLabel,
);

return debounce((text: string): void => {
return debounce((text: string, updateOpen = false): void => {
const filteredData = filter(this.data, text);
const itemsAndGroups = this.getItemsAndGroups();

Expand All @@ -1090,6 +1089,11 @@ export class Combobox
});

this.filteredItems = this.getFilteredItems();

if (updateOpen) {
this.open = this.text.trim().length > 0 && this.filteredItems.length > 0;
}

this.calciteComboboxFilterChange.emit();
}, 100);
})();
Expand Down Expand Up @@ -1259,6 +1263,7 @@ export class Combobox
}
this.updateItems();
this.filterItems("");
this.open = true;
this.emitComboboxChange();
}
}
Expand Down

0 comments on commit 2ba7b5a

Please sign in to comment.