From c2877352ee3ed0114eddc74cd062a71e5fd407b5 Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Sat, 31 Aug 2024 20:13:01 +0800 Subject: [PATCH] Cleanup notice display on no results vs no choices --- src/scripts/choices.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/scripts/choices.ts b/src/scripts/choices.ts index f8fd1052..a1f822be 100644 --- a/src/scripts/choices.ts +++ b/src/scripts/choices.ts @@ -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; @@ -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; } @@ -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); @@ -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, { @@ -1639,8 +1633,6 @@ class Choices { this._stopSearch(); } - this._clearNotice(); - return; }