Skip to content

Commit 553c504

Browse files
fix(AnalyticalTable): fix flickering background colors when alternateRowColors is active (#303)
1 parent eb6c3c9 commit 553c504

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

packages/main/src/components/AnalyticalTable/AnayticalTable.jss.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,11 @@ const styles = ({ parameters }: JSSTheme) => ({
4141
backgroundColor: parameters.sapUiListBackground
4242
},
4343
alternateRowColor: {
44-
'& $tr:nth-child(even)': {
45-
backgroundColor: parameters.sapUiListHeaderBackground
46-
}
44+
backgroundColor: parameters.sapUiListHeaderBackground
4745
},
4846
emptyRow: {},
4947
tr: {
5048
zIndex: 0,
51-
backgroundColor: parameters.sapUiListBackground,
5249
color: parameters.sapUiListTextColor,
5350
'&[data-is-selected]': {
5451
backgroundColor: `${parameters.sapUiListSelectionBackgroundColor} !important`

packages/main/src/components/AnalyticalTable/__snapshots__/AnalyticalTable.test.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ exports[`AnalyticalTable Alternate Row Color 1`] = `
283283
style="position: relative; height: 220px; width: 600px; overflow: auto; will-change: transform; direction: ltr;"
284284
>
285285
<div
286-
class="AnalyticalTable--tbody- AnalyticalTable--alternateRowColor-"
286+
class="AnalyticalTable--tbody-"
287287
style="height: 220px; width: 100%;"
288288
>
289289
<div
@@ -343,7 +343,7 @@ exports[`AnalyticalTable Alternate Row Color 1`] = `
343343
</div>
344344
<div
345345
aria-rowindex="1"
346-
class="AnalyticalTable--tr-"
346+
class="AnalyticalTable--tr- AnalyticalTable--alternateRowColor-"
347347
role="row"
348348
style="position: absolute; left: 0px; top: 44px; height: 44px; width: 100%;"
349349
>
@@ -445,7 +445,7 @@ exports[`AnalyticalTable Alternate Row Color 1`] = `
445445
</div>
446446
<div
447447
aria-rowindex="3"
448-
class="AnalyticalTable--tr- AnalyticalTable--emptyRow-"
448+
class="AnalyticalTable--tr- AnalyticalTable--emptyRow- AnalyticalTable--alternateRowColor-"
449449
role="row"
450450
style="position: absolute; left: 0px; top: 132px; height: 44px; width: 100%;"
451451
>
@@ -3057,7 +3057,7 @@ exports[`AnalyticalTable render without data 1`] = `
30573057
style="position: relative; height: 220px; width: 600px; overflow: auto; will-change: transform; direction: ltr;"
30583058
>
30593059
<div
3060-
class="AnalyticalTable--tbody- AnalyticalTable--alternateRowColor-"
3060+
class="AnalyticalTable--tbody-"
30613061
style="height: 220px; width: 100%;"
30623062
>
30633063
<div
@@ -3109,7 +3109,7 @@ exports[`AnalyticalTable render without data 1`] = `
31093109
</div>
31103110
<div
31113111
aria-rowindex="1"
3112-
class="AnalyticalTable--tr- AnalyticalTable--emptyRow-"
3112+
class="AnalyticalTable--tr- AnalyticalTable--emptyRow- AnalyticalTable--alternateRowColor-"
31133113
role="row"
31143114
style="position: absolute; left: 0px; top: 44px; height: 44px; width: 100%;"
31153115
>
@@ -3203,7 +3203,7 @@ exports[`AnalyticalTable render without data 1`] = `
32033203
</div>
32043204
<div
32053205
aria-rowindex="3"
3206-
class="AnalyticalTable--tr- AnalyticalTable--emptyRow-"
3206+
class="AnalyticalTable--tr- AnalyticalTable--emptyRow- AnalyticalTable--alternateRowColor-"
32073207
role="row"
32083208
style="position: absolute; left: 0px; top: 132px; height: 44px; width: 100%;"
32093209
>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ import { TableSelectionMode } from '@ui5/webcomponents-react/lib/TableSelectionM
44
const ROW_SELECTION_ATTRIBUTE = 'data-is-selected';
55

66
export const useTableRowStyling = (hooks) => {
7-
87
hooks.getRowProps.push((passedRowProps, { instance, row }) => {
9-
const { classes, selectionMode, onRowSelected } = instance.webComponentsReactProperties;
8+
const { classes, selectionMode, onRowSelected, alternateRowColor } = instance.webComponentsReactProperties;
109
const isEmptyRow = row.original?.emptyRow;
1110
let className = classes.tr;
1211
if (row.isGrouped) {
1312
className += ` ${classes.tableGroupHeader}`;
1413
}
1514

16-
if(isEmptyRow) {
15+
if (isEmptyRow) {
1716
className += ` ${classes.emptyRow}`;
1817
}
1918

19+
if (alternateRowColor && row.index % 2 !== 0) {
20+
className += ` ${classes.alternateRowColor}`;
21+
}
22+
2023
const rowProps: any = {
2124
...passedRowProps,
2225
className,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { TitleBar } from './TitleBar';
5252
import { VirtualTableBody } from './virtualization/VirtualTableBody';
5353
import { useDynamicColumnWidths } from './hooks/useDynamicColumnWidths';
5454
import { TableScaleWidthMode } from '../../enums/TableScaleWidthMode';
55-
import {useColumnsDependencies} from "./hooks/useColumnsDependencies";
55+
import { useColumnsDependencies } from './hooks/useColumnsDependencies';
5656

5757
export interface ColumnConfiguration extends Column {
5858
accessor?: string;
@@ -181,7 +181,6 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
181181
return props.data;
182182
}, [props.data, minRows]);
183183

184-
185184
const {
186185
getTableProps,
187186
headerGroups,
@@ -205,6 +204,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
205204
onRowSelected,
206205
onRowExpandChange,
207206
isTreeTable,
207+
alternateRowColor,
208208
// tableClientWidth,
209209
scaleWidthMode
210210
},
@@ -232,7 +232,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
232232
const updateTableClientWidth = useCallback(() => {
233233
requestAnimationFrame(() => {
234234
if (tableRef.current) {
235-
dispatch({ type: 'TABLE_RESIZE', payload: { tableClientWidth: tableRef.current.clientWidth }});
235+
dispatch({ type: 'TABLE_RESIZE', payload: { tableClientWidth: tableRef.current.clientWidth } });
236236
}
237237
});
238238
}, []);
@@ -326,7 +326,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
326326
{title && <TitleBar>{title}</TitleBar>}
327327
{typeof renderExtension === 'function' && <div>{renderExtension()}</div>}
328328
<div className={tableContainerClasses.valueOf()} ref={tableRef}>
329-
{(
329+
{
330330
<div {...getTableProps()} role="table" aria-rowcount={rows.length}>
331331
{headerGroups.map((headerGroup) => {
332332
let headerProps = {};
@@ -395,7 +395,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
395395
/>
396396
)}
397397
</div>
398-
)}
398+
}
399399
</div>
400400
</div>
401401
);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ export const VirtualTableBody = (props) => {
3333
if (selectionMode === TableSelectionMode.SINGLE_SELECT || selectionMode === TableSelectionMode.MULTI_SELECT) {
3434
innerDivRef.current.classList.add(classes.selectable);
3535
}
36-
if (alternateRowColor) {
37-
innerDivRef.current.classList.add(classes.alternateRowColor);
38-
}
3936
}
4037
}, [
4138
innerDivRef.current,

0 commit comments

Comments
 (0)