Skip to content

fix: preserve aria labels for cell and column of table #8515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions packages/react-aria-components/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 (
Expand Down
17 changes: 16 additions & 1 deletion packages/react-aria-components/test/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down Expand Up @@ -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);
Expand Down