Skip to content

Commit

Permalink
fix: cellDomRef is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
myronliu347 authored and 潕量 committed Jun 29, 2022
1 parent d39a374 commit 654dcae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/table/base/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,22 @@ export default class Header extends React.Component {
columnProps.ref(cell);
}
};

getCellDomRef = (i, j, cellDom) => {
createCellDomRef = (i, j) => {
const cellRefKey = this.getCellDomRefKey(i, j);
this[cellRefKey] = cellDom;
if (!this[cellRefKey]) {
this[cellRefKey] = {};
}

return this[cellRefKey];
};

getCellDomRef = (cellRef, cellDom) => {
if (!cellRef) {
return;
}

cellRef.current = cellDom;
};

getCellDomRefKey = (i, j) => {
Expand Down Expand Up @@ -124,7 +136,7 @@ export default class Header extends React.Component {

const header = columns.map((cols, index) => {
const col = cols.map((col, j) => {
const cellRefKey = this.getCellDomRefKey(index, j);
const cellRef = this.createCellDomRef(index, j);
/* eslint-disable no-unused-vars, prefer-const */
let {
title,
Expand Down Expand Up @@ -192,7 +204,7 @@ export default class Header extends React.Component {
rtl={rtl}
dataIndex={dataIndex}
resizeProxyDomRef={resizeProxyDomRef}
cellDomRef={this[cellRefKey]}
cellDomRef={cellRef}
onChange={onResizeChange}
/>
);
Expand Down Expand Up @@ -235,7 +247,7 @@ export default class Header extends React.Component {
align={alignHeader ? alignHeader : align}
className={className}
ref={this.getCellRef.bind(this, index, j)}
getCellDomRef={this.getCellDomRef.bind(this, index, j)}
getCellDomRef={this.getCellDomRef.bind(this, cellRef)}
type="header"
>
{sortElement}
Expand Down
5 changes: 2 additions & 3 deletions src/table/base/resize.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { findDOMNode } from 'react-dom';
import T from 'prop-types';
import { events, dom } from '../../util';

Expand Down Expand Up @@ -77,10 +76,10 @@ class Resize extends React.Component {
};
onMouseDown = e => {
const { left: tableLeft, width: tableWidth } = this.props.tableEl.getBoundingClientRect();
if (!this.props.cellDomRef) {
if (!this.props.cellDomRef || !this.props.cellDomRef.current) {
return;
}
const { left: cellDomLeft } = this.props.cellDomRef.getBoundingClientRect();
const { left: cellDomLeft } = this.props.cellDomRef.current.getBoundingClientRect();
this.lastPageX = e.pageX;
this.tLeft = tableLeft;
this.tRight = tableWidth;
Expand Down

0 comments on commit 654dcae

Please sign in to comment.