mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-30 08:17:44 +02:00
Merge pull request #466 from MareStare/feat/hide-autocomplete-when-no-suggestions
Hide the autocomplete popup entirely if there are no items to show
This commit is contained in:
commit
51ba0deb47
3 changed files with 18 additions and 2 deletions
|
@ -294,7 +294,7 @@ export default tsEslint.config(
|
||||||
'error',
|
'error',
|
||||||
{
|
{
|
||||||
// Custom `expectStuff()` functions must also count as assertions.
|
// Custom `expectStuff()` functions must also count as assertions.
|
||||||
assertFunctionNames: ['expect*', '*.expect*'],
|
assertFunctionNames: ['expect*', '*.expect*', 'assert*'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,7 +61,16 @@ describe('Suggestions', () => {
|
||||||
[popup, input] = mockBaseSuggestionsPopup();
|
[popup, input] = mockBaseSuggestionsPopup();
|
||||||
|
|
||||||
expect(document.querySelector('.autocomplete')).toBeInstanceOf(HTMLElement);
|
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', () => {
|
it('should render suggestions', () => {
|
||||||
|
|
|
@ -321,6 +321,13 @@ export class SuggestionsPopupComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
showForElement(targetElement: HTMLElement) {
|
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.position = 'absolute';
|
||||||
this.container.style.left = `${targetElement.offsetLeft}px`;
|
this.container.style.left = `${targetElement.offsetLeft}px`;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue