11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3- import { log } from '../../util' ;
3+ import { log , dom , events } from '../../util' ;
44import Row from '../lock/row' ;
55
66export default class ExpandedRow extends React . Component {
@@ -21,6 +21,34 @@ export default class ExpandedRow extends React.Component {
2121 lockType : PropTypes . oneOf ( [ 'left' , 'right' ] ) ,
2222 } ;
2323
24+ componentDidMount ( ) {
25+ events . on ( window , 'resize' , this . setExpandedWidth ) ;
26+ }
27+
28+ componentDidUpdate ( ) {
29+ this . setExpandedWidth ( ) ;
30+ }
31+
32+ componentWillUnmount ( ) {
33+ events . off ( window , 'resize' , this . setExpandedWidth ) ;
34+ }
35+
36+ getExpandedRow = ( parentKey , ref ) => {
37+ if ( ! this . expandedRowRef ) {
38+ this . expandedRowRef = { } ;
39+ }
40+ this . expandedRowRef [ parentKey ] = ref ;
41+ } ;
42+
43+ setExpandedWidth = ( ) => {
44+ const { tableEl } = this . props ;
45+ const totalWidth = + ( tableEl && tableEl . clientWidth ) - 2 || '100%' ;
46+
47+ Object . keys ( this . expandedRowRef || { } ) . forEach ( key => {
48+ dom . setStyle ( this . expandedRowRef [ key ] , { width : totalWidth } ) ;
49+ } ) ;
50+ } ;
51+
2452 renderExpandedRow ( record , rowIndex ) {
2553 const {
2654 expandedRowRender,
@@ -30,7 +58,6 @@ export default class ExpandedRow extends React.Component {
3058 expandedIndexSimulate,
3159 expandedRowWidthEquals2Table,
3260 } = this . context ;
33- const { tableOuterWidth } = this . props ;
3461 const expandedIndex = expandedIndexSimulate ? ( rowIndex - 1 ) / 2 : rowIndex ;
3562
3663 const { columns, cellRef } = this . props ;
@@ -76,7 +103,6 @@ export default class ExpandedRow extends React.Component {
76103
77104 const expandedRowStyle = {
78105 position : 'sticky' ,
79- width : ( tableOuterWidth || 0 ) - 1 ,
80106 left : 0 ,
81107 } ;
82108 // 暴露给用户的index
@@ -85,14 +111,19 @@ export default class ExpandedRow extends React.Component {
85111 content = (
86112 < div
87113 className = { `${ prefix } table-cell-wrapper` }
114+ ref = { this . getExpandedRow . bind ( this , record [ primaryKey ] ) }
88115 style = { expandedRowWidthEquals2Table && expandedRowStyle }
89116 >
90117 { content }
91118 </ div >
92119 ) ;
93120 } else {
94121 content = expandedRowWidthEquals2Table ? (
95- < div className = { `${ prefix } table-expanded-area` } style = { expandedRowStyle } >
122+ < div
123+ className = { `${ prefix } table-expanded-area` }
124+ ref = { this . getExpandedRow . bind ( this , record [ primaryKey ] ) }
125+ style = { expandedRowStyle }
126+ >
96127 { content }
97128 </ div >
98129 ) : (
0 commit comments