Skip to content
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

fix(AnalyticalTable): set aria-label correctly for non-interactive tables #5570

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,10 @@ describe('AnalyticalTable', () => {
cellLabel: ({ cell }) => `${cell.cellLabel} custom aria-label`
};
cy.mount(<AnalyticalTable columns={[...columns, customCellColumn]} data={data} groupable filterable sortable />);

cy.get('[data-visible-row-index="1"][data-visible-column-index="0"]').should('have.attr', 'aria-label', 'Name A ');
cy.get('[data-visible-row-index="1"][data-visible-column-index="1"]').should('have.attr', 'aria-label', 'Age 40 ');

cy.findByText('Name').click();
cy.findByText('Sort Ascending').shadow().findByRole('listitem').click({ force: true });
cy.get('[data-column-id="name"]').should('have.attr', 'aria-sort', 'ascending');
Expand All @@ -1953,17 +1957,17 @@ describe('AnalyticalTable', () => {
cy.get('[data-visible-row-index="1"][data-visible-column-index="0"]').should(
'have.attr',
'aria-label',
'Name Grouped, To expand the row, press the spacebar'
'Name A Grouped, To expand the row, press the spacebar'
);
cy.get('[name="navigation-right-arrow"]').click();
cy.get('[data-visible-row-index="1"][data-visible-column-index="0"]').should(
'have.attr',
'aria-label',
'Name Grouped, To collapse the row, press the spacebar'
'Name A Grouped, To collapse the row, press the spacebar'
);
cy.findByText('Name').click();
cy.findByText('Ungroup').shadow().findByRole('listitem').click({ force: true });
cy.get('[data-visible-row-index="1"][data-visible-column-index="0"]').should('have.attr', 'aria-label', 'Name ');
cy.get('[data-visible-row-index="1"][data-visible-column-index="0"]').should('have.attr', 'aria-label', 'Name A ');
cy.get('[data-column-id="name"]')
.should('have.attr', 'aria-sort', 'descending')
.and('have.attr', 'aria-label', 'Filtered');
Expand All @@ -1977,7 +1981,7 @@ describe('AnalyticalTable', () => {
cy.get('[data-visible-row-index="1"][data-visible-column-index="3"]').should(
'have.attr',
'aria-label',
'Custom Label '
'Custom Label 42 '
);
cy.get('[data-visible-row-index="1"][data-visible-column-index="4"]').should(
'have.attr',
Expand Down Expand Up @@ -2942,7 +2946,7 @@ describe('AnalyticalTable', () => {
'aria-label',
'Name Empty'
);
cy.get('[data-visible-row-index="1"][data-visible-column-index="1"]').should('have.attr', 'aria-label', 'Age ');
cy.get('[data-visible-row-index="1"][data-visible-column-index="1"]').should('have.attr', 'aria-label', 'Age 0 ');
cy.get('[data-visible-row-index="1"][data-visible-column-index="2"]').should(
'have.attr',
'aria-label',
Expand All @@ -2953,7 +2957,7 @@ describe('AnalyticalTable', () => {
'aria-label',
'Custom Label Empty'
);
cy.get('[data-visible-row-index="2"][data-visible-column-index="0"]').should('have.attr', 'aria-label', 'Name ');
cy.get('[data-visible-row-index="2"][data-visible-column-index="0"]').should('have.attr', 'aria-label', 'Name A ');
});

cypressPassThroughTestsFactory(AnalyticalTable, { data, columns });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ const setCellProps = (cellProps, { cell, instance }) => {
const isFirstUserCol = userCols[0]?.id === column.id || userCols[0]?.accessor === column.accessor;
updatedCellProps['data-is-first-column'] = isFirstUserCol;
updatedCellProps['aria-label'] = column.headerLabel || (typeof column.Header === 'string' ? column.Header : '');
if (updatedCellProps['aria-label']) {
updatedCellProps['aria-label'] += ' ';
}
updatedCellProps['aria-label'] &&= `${updatedCellProps['aria-label']} `;
updatedCellProps['aria-label'] += value || value === 0 ? `${value} ` : '';

if ((isFirstUserCol && rowIsExpandable) || (row.isGrouped && row.canExpand)) {
updatedCellProps.onKeyDown = row.getToggleRowExpandedProps?.()?.onKeyDown;
Expand All @@ -56,10 +55,10 @@ const setCellProps = (cellProps, { cell, instance }) => {
) {
if (row.isSelected) {
updatedCellProps['aria-selected'] = 'true';
updatedCellProps['aria-label'] += `${value ?? ''} ${translatableTexts.unselectA11yText}`;
updatedCellProps['aria-label'] += ` ${translatableTexts.unselectA11yText}`;
} else {
updatedCellProps['aria-selected'] = 'false';
updatedCellProps['aria-label'] += `${value ?? ''} ${translatableTexts.selectA11yText}`;
updatedCellProps['aria-label'] += ` ${translatableTexts.selectA11yText}`;
}
}
const { cellLabel } = cell.column;
Expand Down
Loading