From 9bdb3a334f34b2ba2a82c024ed3d63522038fdb8 Mon Sep 17 00:00:00 2001 From: MareStare Date: Tue, 18 Mar 2025 23:03:52 +0000 Subject: [PATCH 1/3] Hide the popup entirely if there are no items to show --- assets/js/utils/suggestions-view.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assets/js/utils/suggestions-view.ts b/assets/js/utils/suggestions-view.ts index 361af00e..2454c706 100644 --- a/assets/js/utils/suggestions-view.ts +++ b/assets/js/utils/suggestions-view.ts @@ -321,6 +321,13 @@ export class SuggestionsPopupComponent { } showForElement(targetElement: HTMLElement) { + if (this.items.length === 0) { + // Hide the popup because there are no suggestions to show. We have to do it + // explicitly, because a border is still rendered even for an empty popup. + this.hide(); + return; + } + this.container.style.position = 'absolute'; this.container.style.left = `${targetElement.offsetLeft}px`; From 79c611a6f95caaf069ed17cf2de7f619aa5e93ed Mon Sep 17 00:00:00 2001 From: MareStare Date: Tue, 18 Mar 2025 23:09:37 +0000 Subject: [PATCH 2/3] Add a test for empty behavior --- assets/js/utils/__tests__/suggestion-view.spec.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/js/utils/__tests__/suggestion-view.spec.ts b/assets/js/utils/__tests__/suggestion-view.spec.ts index e6da562d..8facca1c 100644 --- a/assets/js/utils/__tests__/suggestion-view.spec.ts +++ b/assets/js/utils/__tests__/suggestion-view.spec.ts @@ -61,7 +61,16 @@ describe('Suggestions', () => { [popup, input] = mockBaseSuggestionsPopup(); expect(document.querySelector('.autocomplete')).toBeInstanceOf(HTMLElement); - expect(popup.isHidden).toBe(false); + assert(popup.isHidden); + }); + + it('should hide the popup when there are no suggestions to show', () => { + [popup, input] = mockBaseSuggestionsPopup(); + + popup.setSuggestions({ history: [], tags: [] }); + popup.showForElement(input); + + assert(popup.isHidden); }); it('should render suggestions', () => { From e2c491088e7e0074a1fe17703564fe6643ae3d38 Mon Sep 17 00:00:00 2001 From: MareStare Date: Tue, 18 Mar 2025 23:11:13 +0000 Subject: [PATCH 3/3] Add `assert` as an function that "asserts" to eslint config --- assets/eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/eslint.config.js b/assets/eslint.config.js index aaae607d..51715805 100644 --- a/assets/eslint.config.js +++ b/assets/eslint.config.js @@ -294,7 +294,7 @@ export default tsEslint.config( 'error', { // Custom `expectStuff()` functions must also count as assertions. - assertFunctionNames: ['expect*', '*.expect*'], + assertFunctionNames: ['expect*', '*.expect*', 'assert*'], }, ], },