Skip to content

Commit c1e20eb

Browse files
authored
fix(AnalyticalTable): apply alternate row color correctly on sorted rows (#4691)
Fixes #4690 Note: Doesn't work with `nth-child` because of virtualization.
1 parent ddbfb4a commit c1e20eb

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.cy.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,22 +1106,28 @@ describe('AnalyticalTable', () => {
11061106
const alternatingRowColor = cssVarToRgb(ThemingParameters.sapList_AlternatingBackground);
11071107
cy.mount(<AnalyticalTable data={data} columns={columns} alternateRowColor minRows={7} />);
11081108
cy.get('[data-component-name="AnalyticalTableContainer"]').should('have.css', 'background-color', standardRowColor);
1109-
for (let i = 1; i <= 4; i++) {
1110-
if (i % 2) {
1111-
// no color set
1112-
cy.get(`[aria-rowindex="${i}"]`).should('have.css', 'background-color', 'rgba(0, 0, 0, 0)');
1113-
} else {
1114-
cy.get(`[aria-rowindex="${i}"]`).should('have.css', 'background-color', alternatingRowColor);
1109+
function testAlternateRowColor() {
1110+
for (let i = 1; i <= 4; i++) {
1111+
if (i % 2) {
1112+
// no color set
1113+
cy.get(`[aria-rowindex="${i}"]`).should('have.css', 'background-color', 'rgba(0, 0, 0, 0)');
1114+
} else {
1115+
cy.get(`[aria-rowindex="${i}"]`).should('have.css', 'background-color', alternatingRowColor);
1116+
}
11151117
}
1118+
cy.get('[data-empty-row="true"]').each(($emptyRow, i) => {
1119+
if ((i + 1) % 2) {
1120+
// no color set
1121+
cy.wrap($emptyRow).should('have.css', 'background-color', 'rgba(0, 0, 0, 0)');
1122+
} else {
1123+
cy.wrap($emptyRow).should('have.css', 'background-color', alternatingRowColor);
1124+
}
1125+
});
11161126
}
1117-
cy.get('[data-empty-row="true"]').each(($emptyRow, i) => {
1118-
if ((i + 1) % 2) {
1119-
// no color set
1120-
cy.wrap($emptyRow).should('have.css', 'background-color', 'rgba(0, 0, 0, 0)');
1121-
} else {
1122-
cy.wrap($emptyRow).should('have.css', 'background-color', alternatingRowColor);
1123-
}
1124-
});
1127+
testAlternateRowColor();
1128+
cy.findByText('Name').click();
1129+
cy.findByText('Sort Ascending').shadow().findByRole('listitem').click({ force: true });
1130+
testAlternateRowColor();
11251131
});
11261132

11271133
it('initial column order', () => {

packages/main/src/components/AnalyticalTable/TableBody/VirtualTableBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
157157
lastNonEmptyRow.current = row;
158158
}
159159
prepareRow(row);
160-
const rowProps = row.getRowProps();
160+
const rowProps = row.getRowProps({ rowIndex: virtualRow.index });
161161
const isNavigatedCell = markNavigatedRow(row);
162162
const RowSubComponent = typeof renderRowSubComponent === 'function' ? renderRowSubComponent(row) : undefined;
163163

packages/main/src/components/AnalyticalTable/hooks/useStyling.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const getHeaderProps = (columnProps, { instance, column }) => {
4242

4343
const ROW_SELECTION_ATTRIBUTE = 'data-is-selected';
4444

45-
const getRowProps = (rowProps, { instance, row }) => {
45+
const getRowProps = (rowProps, { instance, row, userProps }) => {
4646
const { webComponentsReactProperties } = instance;
4747
const { classes, selectionBehavior, selectionMode, alternateRowColor, subRowsKey } = webComponentsReactProperties;
4848
let className = classes.tr;
@@ -58,8 +58,7 @@ const getRowProps = (rowProps, { instance, row }) => {
5858
) {
5959
className += ` ${classes.tableGroupHeader}`;
6060
}
61-
62-
if (alternateRowColor && row.index % 2 !== 0) {
61+
if (alternateRowColor && userProps.rowIndex % 2 !== 0) {
6362
className += ` ${classes.alternateRowColor}`;
6463
}
6564

0 commit comments

Comments
 (0)