diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.areas.test.tsx b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.areas.test.tsx index d8019f317779..75cefe6630b9 100644 --- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.areas.test.tsx +++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.areas.test.tsx @@ -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('.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)); diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.nestedFocus.test.tsx b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.nestedFocus.test.tsx index b7d742555b95..c00946403a33 100644 --- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.nestedFocus.test.tsx +++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.nestedFocus.test.tsx @@ -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( diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.test.tsx b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.test.tsx index 0ffa797fd8d6..2b25df79a3f5 100644 --- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.test.tsx +++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTableChart.test.tsx @@ -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(() => @@ -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' }), + ); }); diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.test.tsx b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.test.tsx index 0409c0bca803..cb9941ead5e5 100644 --- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.test.tsx +++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.test.tsx @@ -101,47 +101,50 @@ 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.getByRole('button', { name: 'Previous Page' })).toHaveAttribute( 'aria-disabled', 'true', ); - expect(screen.getByTitle('Previous Page')).not.toHaveAttribute('tabindex'); + expect(screen.getByRole('button', { name: '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.getByRole('button', { name: 'Page 3' }).focus(); await userEvent.keyboard('{Enter}'); - screen.getByTitle('Next Page').focus(); + screen.getByRole('button', { name: 'Next Page' }).focus(); await userEvent.keyboard('{Enter}'); - screen.getByTitle('Previous Page').focus(); + screen.getByRole('button', { name: 'Previous Page' }).focus(); await userEvent.keyboard('{Enter}'); - screen.getByTitle('Next 3 Pages').focus(); + screen.getByRole('button', { name: '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(); + screen.getByRole('button', { name: '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( + expect(screen.getByRole('button', { name: 'Next Page' })).toHaveAttribute( 'aria-disabled', 'true', ); - screen.getByTitle('1').focus(); + screen.getByRole('button', { name: 'Page 1' }).focus(); await userEvent.keyboard('{Enter}'); expect(onPageChange).toHaveBeenCalledWith(0); }); @@ -181,35 +184,39 @@ function Controlled({ total }: { total: number }) { test('RB8: after a keyboard page change focus stays on the page control used', async () => { render(); - const two = screen.getByTitle('2'); + const two = screen.getByRole('button', { name: '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( + screen.getByRole('button', { name: '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(); - screen.getByTitle('Next Page').focus(); + screen.getByRole('button', { name: 'Next Page' }).focus(); await userEvent.keyboard('{Enter}'); await waitFor(() => expect(screen.getByTitle('2')).toHaveClass('ant-pagination-item-active'), ); - screen.getByTitle('Next Page').focus(); + screen.getByRole('button', { name: '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.getByRole('button', { name: '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.getByRole('button', { name: 'Page 3' }), + ), ); }); diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.tsx b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.tsx index 1e479f2c1b4e..0817b53aef3b 100644 --- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.tsx +++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/TreeTable/TreeTablePager.tsx @@ -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( (