Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.

Commit 2cf85b2

Browse files
authored
Fix Dropdown filtering bug (#681)
1 parent a7e305b commit 2cf85b2

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

.changeset/pretty-cycles-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@crowdstrike/glide-core': patch
3+
---
4+
5+
- Filterable Dropdown with a custom `filter()` method now calls that method when its input field is empty.

src/dropdown.test.interactions.filterable.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ it('unfilters when an option is selected via Enter', async () => {
141141
expect(options.length).to.equal(11);
142142
});
143143

144+
it('unfilters on Backspace', async () => {
145+
const component = await fixture<GlideCoreDropdown>(
146+
html`<glide-core-dropdown label="Label">
147+
${defaultSlot}
148+
</glide-core-dropdown>`,
149+
);
150+
151+
component.focus();
152+
await sendKeys({ type: 'one' });
153+
await sendKeys({ press: 'Backspace' });
154+
await sendKeys({ press: 'Backspace' });
155+
await sendKeys({ press: 'Backspace' });
156+
157+
const options = [
158+
...component.querySelectorAll('glide-core-dropdown-option'),
159+
].filter(({ hidden }) => !hidden);
160+
161+
expect(options.length).to.equal(11);
162+
});
163+
144164
it('does nothing on Enter when every option is filtered out', async () => {
145165
const component = await fixture<GlideCoreDropdown>(
146166
html`<glide-core-dropdown label="Label" placeholder="Placeholder">

src/dropdown.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,18 @@ export default class GlideCoreDropdown
12841284
this.isInputOverflow =
12851285
this.#inputElementRef.value.scrollWidth >
12861286
this.#inputElementRef.value.clientWidth;
1287+
1288+
// For the case where the selected option is programmatically removed
1289+
// from the DOM. Without this, the value of the input field would still
1290+
// be set to the selected option's `label`. And an ellipsis would still
1291+
// be shown if the `label` was long enough to be truncated.
12871292
} else if (!this.multiple && this.#inputElementRef.value) {
12881293
this.#inputElementRef.value.value = '';
1294+
this.inputValue = '';
1295+
1296+
this.isInputOverflow =
1297+
this.#inputElementRef.value.scrollWidth >
1298+
this.#inputElementRef.value.clientWidth;
12891299
}
12901300
}
12911301

@@ -1836,7 +1846,7 @@ export default class GlideCoreDropdown
18361846

18371847
let options: GlideCoreDropdownOption[] | undefined;
18381848

1839-
if (this.#inputElementRef.value?.value) {
1849+
if (this.#inputElementRef.value) {
18401850
try {
18411851
// It would be convenient for consumers if we passed an array of options
18421852
// as the second argument. The problem is consumers fetch and render new

0 commit comments

Comments
 (0)