Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ test('keyboard, four levels: Tab enters and leaves every nested grid (headers, c
'0 gridcell ',
'0 gridcell Q2',
]);
expect(await walkDeep(2)).toEqual(['0 combobox Page Size:', '0 li 1']);
expect(await walkDeep(2)).toEqual([
'0 combobox Page Size:',
'0 button Page 1',
]);
parentCell(container, 'row-1', 'queue').focus();
const back = await walkDeep(24, true);
expect(back).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@ test('Enter on a page number of the new pager sends the page change once and clo
);
await openFirst();
await screen.findAllByText('2 Steps');
const page = screen.getByTitle('2');
page.focus();
screen.getByLabelText('Page 2').focus();
await userEvent.keyboard('{Enter}');
await waitFor(() =>
expect(onMask).toHaveBeenCalledWith({ ownState: { currentPage: 1 } }),
Expand All @@ -880,5 +879,5 @@ test('Enter on a page number of the new pager sends the page change once and clo
expect(
container.querySelector('.ant-pagination-item-active'),
).toHaveAttribute('title', '2');
expect(document.activeElement).toBe(screen.getByTitle('2'));
expect(document.activeElement).toBe(screen.getByLabelText('Page 2'));
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,32 @@ test('Tab order: select, then page numbers, the jump and Next; disabled Previous
}
expect(order).toEqual([
'Page Size:',
'1',
'2',
'3',
'Page 1',
'Page 2',
'Page 3',
'Next 3 Pages',
'26',
'Page 26',
'Next Page',
]);
expect(screen.getByTitle('Previous Page')).toHaveAttribute(
expect(screen.getByLabelText('Previous Page')).toHaveAttribute(
'aria-disabled',
'true',
);
expect(screen.getByTitle('Previous Page')).not.toHaveAttribute('tabindex');
expect(screen.getByLabelText('Previous Page')).toHaveAttribute(
'tabindex',
'-1',
);
});

test('Enter on a page number, the jump, Next and Previous changes the page once each', async () => {
const { onPageChange } = renderPager({ currentPage: 1 });
screen.getByTitle('3').focus();
screen.getByLabelText('Page 3').focus();
await userEvent.keyboard('{Enter}');
screen.getByTitle('Next Page').focus();
screen.getByLabelText('Next Page').focus();
await userEvent.keyboard('{Enter}');
screen.getByTitle('Previous Page').focus();
screen.getByLabelText('Previous Page').focus();
await userEvent.keyboard('{Enter}');
screen.getByTitle('Next 3 Pages').focus();
screen.getByLabelText('Next 3 Pages').focus();
await userEvent.keyboard('{Enter}');
expect(onPageChange.mock.calls).toEqual([[2], [2], [0], [4]]);
});
Expand All @@ -137,11 +140,11 @@ test('Space on a page number does nothing (platform pager: Enter only)', async (

test('the last page is reached through its number; Next is disabled there', async () => {
const { onPageChange } = renderPager({ currentPage: 25 });
expect(screen.getByTitle('Next Page')).toHaveAttribute(
expect(screen.getByLabelText('Next Page')).toHaveAttribute(
'aria-disabled',
'true',
);
screen.getByTitle('1').focus();
screen.getByLabelText('Page 1').focus();
await userEvent.keyboard('{Enter}');
expect(onPageChange).toHaveBeenCalledWith(0);
});
Expand Down Expand Up @@ -181,35 +184,34 @@ function Controlled({ total }: { total: number }) {

test('RB8: after a keyboard page change focus stays on the page control used', async () => {
render(<Controlled total={1284} />);
const two = screen.getByTitle('2');
two.focus();
screen.getByLabelText('Page 2').focus();
await userEvent.keyboard('{Enter}');
await waitFor(() =>
expect(screen.getByTitle('2')).toHaveClass('ant-pagination-item-active'),
);
await act(() => new Promise(resolve => setTimeout(resolve, 30)));
expect(document.activeElement).toBe(screen.getByTitle('2'));
expect(document.activeElement).toBe(screen.getByLabelText('Page 2'));
});

test('RB8: when the control used goes away (Next on the last page turns disabled), the new current page takes focus', async () => {
render(<Controlled total={120} />);
screen.getByTitle('Next Page').focus();
screen.getByLabelText('Next Page').focus();
await userEvent.keyboard('{Enter}');
await waitFor(() =>
expect(screen.getByTitle('2')).toHaveClass('ant-pagination-item-active'),
);
screen.getByTitle('Next Page').focus();
screen.getByLabelText('Next Page').focus();
await userEvent.keyboard('{Enter}');
await waitFor(() =>
expect(screen.getByTitle('3')).toHaveClass('ant-pagination-item-active'),
);
// jsdom keeps focus on a control that lost its tab stop; a browser drops it
// to the page, which blur() stands in for.
const next = screen.getByTitle('Next Page');
const next = screen.getByLabelText('Next Page');
expect(document.activeElement).toBe(next);
next.setAttribute('tabindex', '0');
act(() => next.blur());
await waitFor(() =>
expect(document.activeElement).toBe(screen.getByTitle('3')),
expect(document.activeElement).toBe(screen.getByLabelText('Page 3')),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface TreeTablePagerProps {
onPageSizeChange: (pageSize: number) => void;
}

const ACTIVE_PAGE = '.ant-pagination-item-active';
const ACTIVE_PAGE = '.ant-pagination-item-active a';
const formatInteger = getNumberFormatter(NumberFormats.INTEGER);

/**
Expand Down
Loading