Skip to content

Commit a953221

Browse files
authored
fix(crud): enable next page button when count is unknown COMPASS-6340 (#3916)
1 parent 34d6f97 commit a953221

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/compass-crud/src/components/crud-toolbar.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,24 @@ describe('CrudToolbar Component', function () {
205205
expect(getPageSpy.calledOnce).to.be.false;
206206
});
207207

208+
it('should have the next page button enabled when count is unknown', function () {
209+
const getPageSpy = sinon.spy();
210+
renderCrudToolbar({
211+
getPage: getPageSpy,
212+
page: 2,
213+
count: undefined,
214+
});
215+
216+
const nextButton = screen.getByTestId('docs-toolbar-next-page-btn');
217+
expect(nextButton).to.have.attribute('aria-disabled', 'false');
218+
219+
expect(getPageSpy.called).to.be.false;
220+
fireEvent.click(nextButton);
221+
222+
expect(getPageSpy.calledOnce).to.be.true;
223+
expect(getPageSpy.firstCall.args[0]).to.equal(3);
224+
});
225+
208226
it('should render the add data button when it is not readonly', function () {
209227
renderCrudToolbar({
210228
readonly: false,

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
155155
const controlId = useId();
156156
const prevButtonDisabled = useMemo(() => page === 0, [page]);
157157
const nextButtonDisabled = useMemo(
158-
() => (count ? 20 * (page + 1) >= count : true),
158+
// If we don't know the count, we can't know if there are more pages.
159+
() =>
160+
count === undefined || count === null ? false : 20 * (page + 1) >= count,
159161
[count, page]
160162
);
161163

0 commit comments

Comments
 (0)