Skip to content

Commit 5a28e3b

Browse files
gersongoulartGerson Goulart
and
Gerson Goulart
authored
#726: Add support for forwarding refs to cell components, allowing for external control or access to the DOM element rendered by the cell. (#727) (Fixes #726)
`ref` is attached to the top-level div element rendered by `FixedDataTableCellDefault` (or `DataCell`). Co-authored-by: Gerson Goulart <[email protected]>
1 parent 3bd68d2 commit 5a28e3b

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

src/FixedDataTableCellDefault.js

+40-39
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,8 @@ import joinClasses from './vendor_upstream/core/joinClasses';
3939
* );
4040
* ```
4141
*/
42-
class FixedDataTableCellDefault extends React.Component {
43-
static propTypes = {
44-
/**
45-
* Outer height of the cell.
46-
*/
47-
height: PropTypes.number,
48-
49-
/**
50-
* Outer width of the cell.
51-
*/
52-
width: PropTypes.number,
53-
54-
/**
55-
* Optional prop that if specified on the `Column` will be passed to the
56-
* cell. It can be used to uniquely identify which column is the cell is in.
57-
*/
58-
columnKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
59-
60-
/**
61-
* Optional prop that represents the rows index in the table.
62-
* For the 'cell' prop of a Column, this parameter will exist for any
63-
* cell in a row with a positive index.
64-
*
65-
* Below that entry point the user is welcome to consume or
66-
* pass the prop through at their discretion.
67-
*/
68-
rowIndex: PropTypes.number,
69-
70-
/**
71-
* Whether this cell is currently within the viewport.
72-
*/
73-
isVisible: PropTypes.bool,
74-
};
75-
76-
render() {
42+
const FixedDataTableCellDefault = React.forwardRef(
43+
function FixedDataTableCellDefault(props, ref) {
7744
//Remove some props which we don't pass into div
7845
const {
7946
height,
@@ -92,8 +59,8 @@ class FixedDataTableCellDefault extends React.Component {
9259
maxWidth,
9360
minWidth,
9461
touchEnabled,
95-
...props
96-
} = this.props;
62+
...cellProps
63+
} = props;
9764

9865
const innerStyle = {
9966
height,
@@ -103,19 +70,53 @@ class FixedDataTableCellDefault extends React.Component {
10370

10471
return (
10572
<div
106-
{...props}
73+
{...cellProps}
10774
className={joinClasses(
10875
cx('fixedDataTableCellLayout/wrap'),
10976
cx('public/fixedDataTableCell/wrap'),
11077
cx('public/fixedDataTableCell/cellContent'),
11178
className
11279
)}
11380
style={innerStyle}
81+
ref={ref}
11482
>
11583
{children}
11684
</div>
11785
);
11886
}
119-
}
87+
);
88+
89+
FixedDataTableCellDefault.propTypes = {
90+
/**
91+
* Outer height of the cell.
92+
*/
93+
height: PropTypes.number,
94+
95+
/**
96+
* Outer width of the cell.
97+
*/
98+
width: PropTypes.number,
99+
100+
/**
101+
* Optional prop that if specified on the `Column` will be passed to the
102+
* cell. It can be used to uniquely identify which column is the cell is in.
103+
*/
104+
columnKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
105+
106+
/**
107+
* Optional prop that represents the rows index in the table.
108+
* For the 'cell' prop of a Column, this parameter will exist for any
109+
* cell in a row with a positive index.
110+
*
111+
* Below that entry point the user is welcome to consume or
112+
* pass the prop through at their discretion.
113+
*/
114+
rowIndex: PropTypes.number,
115+
116+
/**
117+
* Whether this cell is currently within the viewport.
118+
*/
119+
isVisible: PropTypes.bool,
120+
};
120121

121122
export default FixedDataTableCellDefault;

0 commit comments

Comments
 (0)