diff --git a/src/scripts/choices.test.ts b/src/scripts/choices.test.ts index 5d54936..14ed52d 100644 --- a/src/scripts/choices.test.ts +++ b/src/scripts/choices.test.ts @@ -1763,6 +1763,21 @@ describe('choices', () => { instance._onKeyUp({ target: null, keyCode: null }); }); + + it('is fired with a searchFloor of 0', (done) => { + instance.config.searchFloor = 0; + instance.input.value = ''; + instance.input.focus(); + instance.passedElement.element.addEventListener('search', (event) => { + expect(event.detail).to.eql({ + value: instance.input.value, + resultCount: 0, + }); + done(); + }); + + instance._onKeyUp({ target: null, keyCode: null }); + }); }); }); diff --git a/src/scripts/choices.ts b/src/scripts/choices.ts index 62e8f83..a25add9 100644 --- a/src/scripts/choices.ts +++ b/src/scripts/choices.ts @@ -1230,7 +1230,7 @@ class Choices implements Choices { } _handleSearch(value: string): void { - if (!value || !this.input.isFocussed) { + if (!this.input.isFocussed) { return; } @@ -1239,7 +1239,11 @@ class Choices implements Choices { const hasUnactiveChoices = choices.some((option) => !option.active); // Check that we have a value to search and the input was an alphanumeric character - if (value && value.length >= searchFloor) { + if ( + value !== null && + typeof value !== 'undefined' && + value.length >= searchFloor + ) { const resultCount = searchChoices ? this._searchChoices(value) : 0; // Trigger search event this.passedElement.triggerEvent(EVENTS.search, {