Skip to content

Commit da875bf

Browse files
authored
fix ptotential styled performance isssue when using conditional rows/cells (#778)
1 parent f95f329 commit da875bf

File tree

3 files changed

+17
-99
lines changed

3 files changed

+17
-99
lines changed

src/DataTable/TableCell.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ interface TableCellStyleProps {
88
wrapCell: boolean | undefined;
99
allowOverflow: boolean | undefined;
1010
cellStyle: CSSObject | undefined;
11-
extendedCellStyle: CSSObject;
1211
}
1312

1413
const overflowCSS = css<TableCellStyleProps>`
@@ -19,12 +18,13 @@ const overflowCSS = css<TableCellStyleProps>`
1918
}
2019
`;
2120

22-
const TableCellStyle = styled(Cell)<TableCellStyleProps>`
21+
const TableCellStyle = styled(Cell).attrs(props => ({
22+
style: props.style,
23+
}))<TableCellStyleProps>`
2324
font-size: ${({ theme }) => theme.rows.fontSize};
2425
font-weight: 400;
2526
${({ renderAsCell }) => !renderAsCell && overflowCSS};
2627
${({ cellStyle }) => cellStyle};
27-
${({ extendedCellStyle }) => extendedCellStyle};
2828
`;
2929

3030
interface TableCellProps extends TableColumnBase {
@@ -44,7 +44,6 @@ function TableCell({ column, dataTag, extendedCellStyle, id, renderAsCell, child
4444
className="rdt_TableCell"
4545
data-tag={dataTag}
4646
cellStyle={column.style}
47-
extendedCellStyle={extendedCellStyle}
4847
renderAsCell={renderAsCell}
4948
allowOverflow={column.allowOverflow}
5049
button={column.button}
@@ -57,6 +56,7 @@ function TableCell({ column, dataTag, extendedCellStyle, id, renderAsCell, child
5756
right={column.right}
5857
width={column.width}
5958
wrapCell={column.wrap}
59+
style={extendedCellStyle}
6060
>
6161
{children}
6262
</TableCellStyle>

src/DataTable/TableRow.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import styled, { css, CSSObject } from 'styled-components';
2+
import styled, { css } from 'styled-components';
33
import TableCell from './TableCell';
44
import TableCellCheckbox from './TableCellCheckbox';
55
import TableCellExpander from './TableCellExpander';
@@ -23,9 +23,10 @@ const pointerCSS = css`
2323
}
2424
`;
2525

26-
const TableRowStyle = styled.div<{
26+
const TableRowStyle = styled.div.attrs(props => ({
27+
style: props.style,
28+
}))<{
2729
dense?: boolean;
28-
extendedRowStyle?: CSSObject;
2930
highlightOnHover?: boolean;
3031
pointerOnHover?: boolean;
3132
selected?: boolean;
@@ -42,7 +43,6 @@ const TableRowStyle = styled.div<{
4243
${({ highlightOnHover }) => highlightOnHover && highlightCSS};
4344
${({ pointerOnHover }) => pointerOnHover && pointerCSS};
4445
${({ selected, theme }) => selected && theme.rows.selectedHighlightStyle};
45-
${({ extendedRowStyle }) => extendedRowStyle};
4646
`;
4747

4848
type DProps<T> = Pick<
@@ -171,8 +171,8 @@ function TableRow<T extends RowRecord>({
171171
onClick={handleRowClick}
172172
onDoubleClick={handleRowDoubleClick}
173173
className="rdt_TableRow"
174-
extendedRowStyle={extendedRowStyle}
175174
selected={hightlightSelected}
175+
style={extendedRowStyle}
176176
>
177177
{selectableRows && (
178178
<TableCellCheckbox

src/DataTable/__tests__/__snapshots__/DataTable.test.tsx.snap

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10724,7 +10724,6 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1072410724

1072510725
.c12 {
1072610726
font-weight: 400;
10727-
background-color: rgba(63,195,128,0.9);
1072810727
}
1072910728

1073010729
.c12 div:first-child {
@@ -10733,16 +10732,6 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1073310732
text-overflow: ellipsis;
1073410733
}
1073510734

10736-
.c13 {
10737-
font-weight: 400;
10738-
}
10739-
10740-
.c13 div:first-child {
10741-
white-space: nowrap;
10742-
overflow: hidden;
10743-
text-overflow: ellipsis;
10744-
}
10745-
1074610735
.c10 {
1074710736
display: -webkit-box;
1074810737
display: -webkit-flex;
@@ -10871,6 +10860,7 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1087110860
data-tag="allowRowEvents"
1087210861
id="cell-1-1"
1087310862
role="gridcell"
10863+
style="background-color: rgba(63, 195, 128, 0.9);"
1087410864
>
1087510865
<div
1087610866
data-tag="allowRowEvents"
@@ -10885,7 +10875,7 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1088510875
role="row"
1088610876
>
1088710877
<div
10888-
class="c11 c6 c13 rdt_TableCell"
10878+
class="c11 c6 c12 rdt_TableCell"
1088910879
data-tag="allowRowEvents"
1089010880
id="cell-1-2"
1089110881
role="gridcell"
@@ -11263,7 +11253,6 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1126311253

1126411254
.c12 {
1126511255
font-weight: 400;
11266-
color: pink;
1126711256
}
1126811257

1126911258
.c12 div:first-child {
@@ -11272,16 +11261,6 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1127211261
text-overflow: ellipsis;
1127311262
}
1127411263

11275-
.c13 {
11276-
font-weight: 400;
11277-
}
11278-
11279-
.c13 div:first-child {
11280-
white-space: nowrap;
11281-
overflow: hidden;
11282-
text-overflow: ellipsis;
11283-
}
11284-
1128511264
.c10 {
1128611265
display: -webkit-box;
1128711266
display: -webkit-flex;
@@ -11410,6 +11389,7 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1141011389
data-tag="allowRowEvents"
1141111390
id="cell-1-1"
1141211391
role="gridcell"
11392+
style="color: pink;"
1141311393
>
1141411394
<div
1141511395
data-tag="allowRowEvents"
@@ -11424,7 +11404,7 @@ exports[`DataTable::conditionalCellStyles should render correctly when condition
1142411404
role="row"
1142511405
>
1142611406
<div
11427-
class="c11 c6 c13 rdt_TableCell"
11407+
class="c11 c6 c12 rdt_TableCell"
1142811408
data-tag="allowRowEvents"
1142911409
id="cell-1-2"
1143011410
role="gridcell"
@@ -11828,8 +11808,6 @@ exports[`DataTable::conditionalRowStyles should render correctly when conditiona
1182811808
color: rgba(0,0,0,0.87);
1182911809
background-color: #FFFFFF;
1183011810
min-height: 48px;
11831-
background-color: rgba(63,195,128,0.9);
11832-
color: white;
1183311811
}
1183411812

1183511813
.c10:not(:last-of-type) {
@@ -11838,36 +11816,6 @@ exports[`DataTable::conditionalRowStyles should render correctly when conditiona
1183811816
border-bottom-color: rgba(0,0,0,.12);
1183911817
}
1184011818

11841-
.c10:hover {
11842-
cursor: pointer;
11843-
}
11844-
11845-
.c13 {
11846-
display: -webkit-box;
11847-
display: -webkit-flex;
11848-
display: -ms-flexbox;
11849-
display: flex;
11850-
-webkit-align-items: stretch;
11851-
-webkit-box-align: stretch;
11852-
-ms-flex-align: stretch;
11853-
align-items: stretch;
11854-
-webkit-align-content: stretch;
11855-
-ms-flex-line-pack: stretch;
11856-
align-content: stretch;
11857-
width: 100%;
11858-
box-sizing: border-box;
11859-
font-size: 13px;
11860-
color: rgba(0,0,0,0.87);
11861-
background-color: #FFFFFF;
11862-
min-height: 48px;
11863-
}
11864-
11865-
.c13:not(:last-of-type) {
11866-
border-bottom-style: solid;
11867-
border-bottom-width: 1px;
11868-
border-bottom-color: rgba(0,0,0,.12);
11869-
}
11870-
1187111819
.c7 {
1187211820
-webkit-align-items: center;
1187311821
-webkit-box-align: center;
@@ -11964,6 +11912,7 @@ exports[`DataTable::conditionalRowStyles should render correctly when conditiona
1196411912
class="c10 rdt_TableRow"
1196511913
id="row-1"
1196611914
role="row"
11915+
style="background-color: rgba(63, 195, 128, 0.9); color: white;"
1196711916
>
1196811917
<div
1196911918
class="c11 c6 c12 rdt_TableCell"
@@ -11979,7 +11928,7 @@ exports[`DataTable::conditionalRowStyles should render correctly when conditiona
1197911928
</div>
1198011929
</div>
1198111930
<div
11982-
class="c13 rdt_TableRow"
11931+
class="c10 rdt_TableRow"
1198311932
id="row-2"
1198411933
role="row"
1198511934
>
@@ -26651,8 +26600,6 @@ exports[`should render correctly when conditionalRowStyles is used with an expan
2665126600
color: rgba(0,0,0,0.87);
2665226601
background-color: #FFFFFF;
2665326602
min-height: 48px;
26654-
background-color: rgba(63,195,128,0.9);
26655-
color: white;
2665626603
}
2665726604

2665826605
.c12:not(:last-of-type) {
@@ -26661,36 +26608,6 @@ exports[`should render correctly when conditionalRowStyles is used with an expan
2666126608
border-bottom-color: rgba(0,0,0,.12);
2666226609
}
2666326610

26664-
.c12:hover {
26665-
cursor: pointer;
26666-
}
26667-
26668-
.c18 {
26669-
display: -webkit-box;
26670-
display: -webkit-flex;
26671-
display: -ms-flexbox;
26672-
display: flex;
26673-
-webkit-align-items: stretch;
26674-
-webkit-box-align: stretch;
26675-
-ms-flex-align: stretch;
26676-
align-items: stretch;
26677-
-webkit-align-content: stretch;
26678-
-ms-flex-line-pack: stretch;
26679-
align-content: stretch;
26680-
width: 100%;
26681-
box-sizing: border-box;
26682-
font-size: 13px;
26683-
color: rgba(0,0,0,0.87);
26684-
background-color: #FFFFFF;
26685-
min-height: 48px;
26686-
}
26687-
26688-
.c18:not(:last-of-type) {
26689-
border-bottom-style: solid;
26690-
border-bottom-width: 1px;
26691-
border-bottom-color: rgba(0,0,0,.12);
26692-
}
26693-
2669426611
.c9 {
2669526612
-webkit-align-items: center;
2669626613
-webkit-box-align: center;
@@ -26797,6 +26714,7 @@ exports[`should render correctly when conditionalRowStyles is used with an expan
2679726714
class="c12 rdt_TableRow"
2679826715
id="row-1"
2679926716
role="row"
26717+
style="background-color: rgba(63, 195, 128, 0.9); color: white;"
2680026718
>
2680126719
<div
2680226720
class="c13 c14"
@@ -26850,7 +26768,7 @@ exports[`should render correctly when conditionalRowStyles is used with an expan
2685026768
</div>
2685126769
</div>
2685226770
<div
26853-
class="c18 rdt_TableRow"
26771+
class="c12 rdt_TableRow"
2685426772
id="row-2"
2685526773
role="row"
2685626774
>

0 commit comments

Comments
 (0)