Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1112,16 +1112,19 @@ test('keyboard: forward Tab leaves an empty area in the last row and a last step
parentCell(container, 'row-1', 'channel').focus();
expect(await walk(3)).toEqual([
'parent combobox Page Size:',
'parent li 1',
'parent li 2',
'parent button Page 1',
'parent button Page 2',
]);
expect(await walk(3, true)).toEqual([
'parent li 1',
'parent button Page 1',
'parent combobox Page Size:',
'parent gridcell Chat',
]);
container.querySelector<HTMLElement>('.ag-full-width-row')!.focus();
expect(await walk(2)).toEqual(['parent combobox Page Size:', 'parent li 1']);
expect(await walk(2)).toEqual([
'parent combobox Page Size:',
'parent button Page 1',
]);

await userEvent.click(parentButton(container, 1));
await userEvent.click(parentButton(container, 0));
Expand Down
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,7 +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');
const page = screen.getByRole('button', { name: 'Page 2' });
page.focus();
await userEvent.keyboard('{Enter}');
await waitFor(() =>
Expand All @@ -880,5 +880,7 @@ 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.getByRole('button', { name: 'Page 2' }),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function renderPager(extra: Partial<TreeTablePagerProps> = {}) {
return { ...view, onPageChange, onPageSizeChange };
}

/** The focusable control inside a pager item, found by its accessible name. */
const control = (name: string) => screen.getByRole('button', { name });
Comment thread
hainenber marked this conversation as resolved.
Resolved

/** The accessible name or text of the focused element, as the tests read it. */
const focusName = () => {
const element = document.activeElement as HTMLElement;
Expand Down Expand Up @@ -101,47 +104,41 @@ 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(
'aria-disabled',
'true',
);
expect(screen.getByTitle('Previous Page')).not.toHaveAttribute('tabindex');
expect(control('Previous Page')).toHaveAttribute('aria-disabled', 'true');
expect(control('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();
control('Page 3').focus();
await userEvent.keyboard('{Enter}');
screen.getByTitle('Next Page').focus();
control('Next Page').focus();
await userEvent.keyboard('{Enter}');
screen.getByTitle('Previous Page').focus();
control('Previous Page').focus();
await userEvent.keyboard('{Enter}');
screen.getByTitle('Next 3 Pages').focus();
control('Next 3 Pages').focus();
await userEvent.keyboard('{Enter}');
expect(onPageChange.mock.calls).toEqual([[2], [2], [0], [4]]);
});

test('Space on a page number does nothing (platform pager: Enter only)', async () => {
test('Space on a page number changes the page once, like Enter (button semantics)', async () => {
const { onPageChange } = renderPager();
screen.getByTitle('2').focus();
control('Page 2').focus();
await userEvent.keyboard(' ');
expect(onPageChange).not.toHaveBeenCalled();
expect(onPageChange.mock.calls).toEqual([[1]]);
});

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(
'aria-disabled',
'true',
);
screen.getByTitle('1').focus();
expect(control('Next Page')).toHaveAttribute('aria-disabled', 'true');
control('Page 1').focus();
await userEvent.keyboard('{Enter}');
expect(onPageChange).toHaveBeenCalledWith(0);
});
Expand Down Expand Up @@ -181,35 +178,33 @@ 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');
const two = control('Page 2');
two.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(control('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();
control('Next Page').focus();
await userEvent.keyboard('{Enter}');
await waitFor(() =>
expect(screen.getByTitle('2')).toHaveClass('ant-pagination-item-active'),
);
screen.getByTitle('Next Page').focus();
control('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 = control('Next Page');
expect(document.activeElement).toBe(next);
next.setAttribute('tabindex', '0');
act(() => next.blur());
await waitFor(() =>
expect(document.activeElement).toBe(screen.getByTitle('3')),
);
await waitFor(() => expect(document.activeElement).toBe(control('Page 3')));
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export interface TreeTablePagerProps {
onPageSizeChange: (pageSize: number) => void;
}

const ACTIVE_PAGE = '.ant-pagination-item-active';
// The focusable control is inside the list item, not the item itself.
const ACTIVE_PAGE = '.ant-pagination-item-active > [tabindex]';
const formatInteger = getNumberFormatter(NumberFormats.INTEGER);

/**
* The parent grid's pager: a "Page Size:" select and the core pager as the
* list screens use it (Tab reaches each control, Enter changes the page).
* list screens use it (Tab reaches each control, Enter or Space changes the
* page).
*/
const TreeTablePager = forwardRef<HTMLDivElement, TreeTablePagerProps>(
(
Expand Down
Loading