Skip to content

Commit 6f50cb1

Browse files
Fix DataTable type error when clicking on headers (#6781)
* Resolves `DataTable` type error. * Adds changeset Co-authored-by: Alex Page <[email protected]>
1 parent 51be08e commit 6f50cb1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.changeset/strange-vans-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Fixed console error in `DataTable` that is triggered by sorting data via table headers

polaris-react/src/components/DataTable/DataTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
234234
styles.FixedFirstColumn,
235235
!isScrolledFarthestLeft && styles.separate,
236236
)}
237-
style={{maxWidth: `${columnVisibilityData[0].rightEdge}px`}}
237+
style={{maxWidth: `${columnVisibilityData[0]?.rightEdge}px`}}
238238
>
239239
<thead>
240240
<tr style={{height: `${headerRowHeights[0]}px`}}>
@@ -541,7 +541,7 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
541541
const tableRightEdge = tableScrollLeft + tableViewableWidth;
542542
const firstColumnWidth =
543543
this.state.columnVisibilityData.length > 0
544-
? this.state.columnVisibilityData[0].rightEdge
544+
? this.state.columnVisibilityData[0]?.rightEdge
545545
: 0;
546546
const currentColumnLeftEdge = currentCell.offsetLeft;
547547
const currentColumnRightEdge =
@@ -599,7 +599,7 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
599599
const currentCell = event.target.parentNode as HTMLTableCellElement;
600600
const fixedFirstColumn = this.props;
601601
const firstColumnWidth = fixedFirstColumn
602-
? this.state.columnVisibilityData[0].rightEdge
602+
? this.state.columnVisibilityData[0]?.rightEdge
603603
: 0;
604604
const currentColumnLeftEdge = currentCell.offsetLeft;
605605
const desiredScrollLeft = currentColumnLeftEdge - firstColumnWidth;

0 commit comments

Comments
 (0)