Skip to content

Commit

Permalink
fix: take empty field into account (#1250)
Browse files Browse the repository at this point in the history
* fix: take empty field into account

* test: add unit test
  • Loading branch information
DanielS-Qlik committed May 2, 2023
1 parent 63c4196 commit b11e9c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apis/nucleus/src/components/listbox/ListBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ export default function ListBox({
selectDisabled,
layout,
});
}

if (itemsLoader.pages.length && !awaitingFrequencyMax) {
// All necessary data fetching done - signal rendering done!
renderedCallback?.();
}
const cardinal = layout?.qListObject.qDimensionInfo.qCardinal;

if ((itemsLoader?.pages.length && !awaitingFrequencyMax) || cardinal === 0) {
// All necessary data fetching done - signal rendering done!
renderedCallback?.();
}

const isItemLoaded = useCallback(
Expand Down Expand Up @@ -307,7 +309,7 @@ export default function ListBox({
return (
<StyledWrapper>
<ScreenReaderForSelections className="screenReaderOnly" layout={layout} />
{!listCount && <ListBoxDisclaimer width={width} text="Listbox.NoMatchesForYourTerms" />}
{!listCount && cardinal > 0 && <ListBoxDisclaimer width={width} text="Listbox.NoMatchesForYourTerms" />}
<InfiniteLoader
isItemLoaded={isItemLoaded}
itemCount={listCount || 1} // must be more than 0 or loadMoreItems will never be called again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,20 @@ describe('<Listbox />', () => {

test('should render a disclaimer when list count is 0 but should still render a list component', async () => {
layout.qListObject.qSize.qcy = 0;
layout.qListObject.qDimensionInfo.qCardinal = 1;
await render();
const disclaimers = renderer.root.findAllByType(ListBoxDisclaimer);
expect(disclaimers).toHaveLength(1);
const listRows = renderer.root.findAllByProps({ className: 'a-value-row' });
expect(listRows).toHaveLength(1);
});

test('should not render a disclaimer when list count is 0 and qCardinal is 0', async () => {
layout.qListObject.qSize.qcy = 0;
layout.qListObject.qDimensionInfo.qCardinal = 0;
await render();
const disclaimers = renderer.root.findAllByType(ListBoxDisclaimer);
expect(disclaimers).toHaveLength(0);
});
});
});

0 comments on commit b11e9c9

Please sign in to comment.