@@ -627,6 +627,53 @@ const autoFitColumnWidth = async (table, col) => {
627627 }
628628}
629629
630+ const formControlSelector = 'input.form-control:not([type="hidden"]), textarea.form-control' ;
631+
632+ const getHorizontalWidth = style => {
633+ return ( parseFloat ( style . getPropertyValue ( 'padding-left' ) ) || 0 )
634+ + ( parseFloat ( style . getPropertyValue ( 'padding-right' ) ) || 0 )
635+ + ( parseFloat ( style . getPropertyValue ( 'border-left-width' ) ) || 0 )
636+ + ( parseFloat ( style . getPropertyValue ( 'border-right-width' ) ) || 0 ) ;
637+ }
638+
639+ const getFormControlTextWidth = control => {
640+ const style = getComputedStyle ( control ) ;
641+ const span = document . createElement ( 'span' ) ;
642+ span . textContent = control . value || control . getAttribute ( 'placeholder' ) || ' ' ;
643+ span . style . setProperty ( 'visibility' , 'hidden' ) ;
644+ span . style . setProperty ( 'white-space' , 'pre' ) ;
645+ span . style . setProperty ( 'display' , 'inline-block' ) ;
646+ span . style . setProperty ( 'position' , 'absolute' ) ;
647+ span . style . setProperty ( 'top' , '0' ) ;
648+ span . style . setProperty ( 'font-family' , style . getPropertyValue ( 'font-family' ) ) ;
649+ span . style . setProperty ( 'font-size' , style . getPropertyValue ( 'font-size' ) ) ;
650+ span . style . setProperty ( 'font-style' , style . getPropertyValue ( 'font-style' ) ) ;
651+ span . style . setProperty ( 'font-weight' , style . getPropertyValue ( 'font-weight' ) ) ;
652+ span . style . setProperty ( 'letter-spacing' , style . getPropertyValue ( 'letter-spacing' ) ) ;
653+ span . style . setProperty ( 'text-transform' , style . getPropertyValue ( 'text-transform' ) ) ;
654+ document . body . appendChild ( span ) ;
655+
656+ const width = getWidth ( span ) + getHorizontalWidth ( style ) ;
657+ span . remove ( ) ;
658+
659+ return width ;
660+ }
661+
662+ const resetFormControlWidth = ( sourceCell , cloneCell ) => {
663+ const controls = [ ...sourceCell . querySelectorAll ( formControlSelector ) ] ;
664+ const cloneControls = [ ...cloneCell . querySelectorAll ( formControlSelector ) ] ;
665+ controls . forEach ( ( control , index ) => {
666+ const cloneControl = cloneControls [ index ] ;
667+ if ( cloneControl ) {
668+ const width = getFormControlTextWidth ( control ) ;
669+ cloneControl . value = control . value ;
670+ cloneControl . style . setProperty ( 'width' , `${ width } px` , 'important' ) ;
671+ cloneControl . style . setProperty ( 'min-width' , '0' , 'important' ) ;
672+ cloneControl . style . setProperty ( 'flex' , '0 0 auto' , 'important' ) ;
673+ }
674+ } ) ;
675+ }
676+
630677const calcCellWidth = cell => {
631678 const div = document . createElement ( 'div' ) ;
632679 [ ...cell . children ] . forEach ( c => {
@@ -638,9 +685,13 @@ const calcCellWidth = cell => {
638685 div . style . setProperty ( 'position' , 'absolute' ) ;
639686 div . style . setProperty ( 'top' , '0' ) ;
640687 document . body . appendChild ( div ) ;
688+ resetFormControlWidth ( cell , div ) ;
641689
642690 const cellStyle = getComputedStyle ( cell ) ;
643- return getWidth ( div ) + parseFloat ( cellStyle . getPropertyValue ( 'padding-left' ) ) + parseFloat ( cellStyle . getPropertyValue ( 'padding-right' ) ) + parseFloat ( cellStyle . getPropertyValue ( 'border-left-width' ) ) + parseFloat ( cellStyle . getPropertyValue ( 'border-right-width' ) ) + 1 | 0 ;
691+ const width = getWidth ( div ) + getHorizontalWidth ( cellStyle ) + 1 | 0 ;
692+ div . remove ( ) ;
693+
694+ return width ;
644695}
645696
646697const closeAllTips = ( columns , self ) => {
0 commit comments