From f72d33abb962953a70b34e68c1a7bc3f0c1cd8f1 Mon Sep 17 00:00:00 2001 From: seunggabi Date: Sat, 28 Nov 2026 16:41:37 +0900 Subject: [PATCH 1/2] fix(ag-grid-table): restore pager focus and update TreeTable tests for antd 6.7.0 antd 6.7.0 (#46269) pulls @rc-component/pagination 1.7.0, which moves keyboard focus from the pager list item to the link or button inside it. TreeTablePager (#46490) still called focus() on the list item, so focus was no longer restored to the current page when the control in use turned disabled. Target the focusable control instead, and update the tests for the new accessible names, tab stops and Space activation. --- .../TreeTable/TreeTableChart.areas.test.tsx | 11 ++-- .../TreeTableChart.nestedFocus.test.tsx | 5 +- .../src/TreeTable/TreeTableChart.test.tsx | 6 ++- .../src/TreeTable/TreeTablePager.test.tsx | 53 +++++++++---------- .../src/TreeTable/TreeTablePager.tsx | 6 ++- 5 files changed, 43 insertions(+), 38 deletions(-) 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..2c41e64012b4 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 @@ -43,6 +43,9 @@ function renderPager(extra: Partial = {}) { return { ...view, onPageChange, onPageSizeChange }; } +/** The focusable control inside a pager item, found by its accessible name. */ +const control = (name: string) => screen.getByRole('button', { name }); + /** The accessible name or text of the focused element, as the tests read it. */ const focusName = () => { const element = document.activeElement as HTMLElement; @@ -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); }); @@ -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(); - 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(); - 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'))); }); 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( ( From a559735026c58bea72b0bde2f09c9628625dd0d6 Mon Sep 17 00:00:00 2001 From: seunggabi Date: Sat, 28 Nov 2026 17:32:59 +0900 Subject: [PATCH 2/2] test(ag-grid-table): inline screen.getByRole in the pager test --- .../src/TreeTable/TreeTablePager.test.tsx | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) 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 2c41e64012b4..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 @@ -43,9 +43,6 @@ function renderPager(extra: Partial = {}) { return { ...view, onPageChange, onPageSizeChange }; } -/** The focusable control inside a pager item, found by its accessible name. */ -const control = (name: string) => screen.getByRole('button', { name }); - /** The accessible name or text of the focused element, as the tests read it. */ const focusName = () => { const element = document.activeElement as HTMLElement; @@ -111,34 +108,43 @@ test('Tab order: select, then page numbers, the jump and Next; disabled Previous 'Page 26', 'Next Page', ]); - expect(control('Previous Page')).toHaveAttribute('aria-disabled', 'true'); - expect(control('Previous Page')).toHaveAttribute('tabindex', '-1'); + expect(screen.getByRole('button', { name: 'Previous Page' })).toHaveAttribute( + 'aria-disabled', + 'true', + ); + 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 }); - control('Page 3').focus(); + screen.getByRole('button', { name: 'Page 3' }).focus(); await userEvent.keyboard('{Enter}'); - control('Next Page').focus(); + screen.getByRole('button', { name: 'Next Page' }).focus(); await userEvent.keyboard('{Enter}'); - control('Previous Page').focus(); + screen.getByRole('button', { name: 'Previous Page' }).focus(); await userEvent.keyboard('{Enter}'); - control('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 changes the page once, like Enter (button semantics)', async () => { const { onPageChange } = renderPager(); - control('Page 2').focus(); + screen.getByRole('button', { name: 'Page 2' }).focus(); await userEvent.keyboard(' '); 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(control('Next Page')).toHaveAttribute('aria-disabled', 'true'); - control('Page 1').focus(); + expect(screen.getByRole('button', { name: 'Next Page' })).toHaveAttribute( + 'aria-disabled', + 'true', + ); + screen.getByRole('button', { name: 'Page 1' }).focus(); await userEvent.keyboard('{Enter}'); expect(onPageChange).toHaveBeenCalledWith(0); }); @@ -178,33 +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 = control('Page 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(control('Page 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(); - control('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'), ); - control('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 = control('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(control('Page 3'))); + await waitFor(() => + expect(document.activeElement).toBe( + screen.getByRole('button', { name: 'Page 3' }), + ), + ); });