Skip to content

Commit

Permalink
Fix DataTable type error when clicking on headers (#6781)
Browse files Browse the repository at this point in the history
* Resolves `DataTable` type error.

* Adds changeset

Co-authored-by: Alex Page <hi@alexpage.dev>
  • Loading branch information
philschoefer and alex-page committed Jul 28, 2022
1 parent 51be08e commit 6f50cb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-vans-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Fixed console error in `DataTable` that is triggered by sorting data via table headers
6 changes: 3 additions & 3 deletions polaris-react/src/components/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
styles.FixedFirstColumn,
!isScrolledFarthestLeft && styles.separate,
)}
style={{maxWidth: `${columnVisibilityData[0].rightEdge}px`}}
style={{maxWidth: `${columnVisibilityData[0]?.rightEdge}px`}}
>
<thead>
<tr style={{height: `${headerRowHeights[0]}px`}}>
Expand Down Expand Up @@ -541,7 +541,7 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
const tableRightEdge = tableScrollLeft + tableViewableWidth;
const firstColumnWidth =
this.state.columnVisibilityData.length > 0
? this.state.columnVisibilityData[0].rightEdge
? this.state.columnVisibilityData[0]?.rightEdge
: 0;
const currentColumnLeftEdge = currentCell.offsetLeft;
const currentColumnRightEdge =
Expand Down Expand Up @@ -599,7 +599,7 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
const currentCell = event.target.parentNode as HTMLTableCellElement;
const fixedFirstColumn = this.props;
const firstColumnWidth = fixedFirstColumn
? this.state.columnVisibilityData[0].rightEdge
? this.state.columnVisibilityData[0]?.rightEdge
: 0;
const currentColumnLeftEdge = currentCell.offsetLeft;
const desiredScrollLeft = currentColumnLeftEdge - firstColumnWidth;
Expand Down

0 comments on commit 6f50cb1

Please sign in to comment.