From abae50eb727296a43644a669f958c554ed7938b2 Mon Sep 17 00:00:00 2001 From: ctith Date: Wed, 9 Jul 2025 15:16:01 -0500 Subject: [PATCH] fix: preserve aria labels for cell and column of table --- packages/react-aria-components/src/Table.tsx | 4 ++-- .../react-aria-components/test/Table.test.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/react-aria-components/src/Table.tsx b/packages/react-aria-components/src/Table.tsx index 09dbe635f85..e7346182641 100644 --- a/packages/react-aria-components/src/Table.tsx +++ b/packages/react-aria-components/src/Table.tsx @@ -746,7 +746,7 @@ export const Column = /*#__PURE__*/ createLeafComponent('column', (props: Column } let TH = useElementType('th'); - let DOMProps = filterDOMProps(props as any, {global: true}); + let DOMProps = filterDOMProps(props as any, {global: true, labelable: true}); delete DOMProps.id; return ( @@ -1239,7 +1239,7 @@ export const Cell = /*#__PURE__*/ createLeafComponent('cell', (props: CellProps, }); let TD = useElementType('td'); - let DOMProps = filterDOMProps(props as any, {global: true}); + let DOMProps = filterDOMProps(props as any, {global: true, labelable: true}); delete DOMProps.id; return ( diff --git a/packages/react-aria-components/test/Table.test.js b/packages/react-aria-components/test/Table.test.js index 738fc8643fc..590fa1bed81 100644 --- a/packages/react-aria-components/test/Table.test.js +++ b/packages/react-aria-components/test/Table.test.js @@ -334,6 +334,21 @@ describe('Table', () => { } }); + it('should support aria-label props on column and cells', () => { + let {getAllByRole} = renderTable({ + columnProps: {'aria-label': 'aria column label'}, + cellProps: {'aria-label': 'aria cell label'} + }); + + for (let cell of getAllByRole('columnheader')) { + expect(cell).toHaveAttribute('aria-label', 'aria column label'); + } + + for (let cell of getAllByRole('gridcell')) { + expect(cell).toHaveAttribute('aria-label', 'aria cell label'); + } + }); + it('should render checkboxes for selection', async () => { let {getAllByRole} = renderTable({ tableProps: {selectionMode: 'multiple'} @@ -2649,7 +2664,7 @@ describe('Table', () => { let {getByRole} = renderTable({rowProps: {onAction, onPressStart, onPressEnd, onPress, onClick}}); let tableTester = testUtilUser.createTester('Table', {root: getByRole('grid')}); await tableTester.triggerRowAction({row: 1, interactionType}); - + expect(onAction).toHaveBeenCalledTimes(1); expect(onPressStart).toHaveBeenCalledTimes(1); expect(onPressEnd).toHaveBeenCalledTimes(1);