Skip to content

Commit

Permalink
Cleanup notice display on no results vs no choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Aug 31, 2024
1 parent 2d474d6 commit c287735
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/scripts/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ class Choices {
clearStore(): this {
this.itemList.element.replaceChildren('');
this.choiceList.element.replaceChildren('');
this._clearNotice();
this._stopSearch();
this._store.reset();
this._lastAddedChoiceId = 0;
this._lastAddedGroupId = 0;
Expand All @@ -859,11 +859,7 @@ class Choices {
clearInput(): this {
const shouldSetInputWidth = !this._isSelectOneElement;
this.input.clear(shouldSetInputWidth);
this._clearNotice();

if (this._isSearching) {
this._stopSearch();
}
this._stopSearch();

return this;
}
Expand Down Expand Up @@ -999,17 +995,14 @@ class Choices {
}
}

const notice = this._notice;
if (!selectableChoices) {
if (!notice) {
if (!this._notice) {
this._notice = {
text: resolveStringFunction(config.noChoicesText),
type: NoticeTypes.noChoices,
text: resolveStringFunction(isSearching ? config.noResultsText : config.noChoicesText),
type: isSearching ? NoticeTypes.noResults : NoticeTypes.noChoices,
};
}
fragment.replaceChildren('');
} else if (notice && notice.type === NoticeTypes.noChoices) {
this._notice = undefined;
}

this._renderNotice(fragment);
Expand Down Expand Up @@ -1464,6 +1457,7 @@ class Choices {
this._currentValue = '';
this._isSearching = false;
if (wasSearching) {
this._clearNotice();
this._store.dispatch(activateChoices(true));

this.passedElement.triggerEvent(EventType.search, {
Expand Down Expand Up @@ -1639,8 +1633,6 @@ class Choices {
this._stopSearch();
}

this._clearNotice();

return;
}

Expand Down

0 comments on commit c287735

Please sign in to comment.