1- import { useState } from 'react' ;
1+ import { useRef , useState } from 'react' ;
22import { css } from '@linaria/core' ;
33
44import { useRovingTabIndex } from './hooks' ;
@@ -85,6 +85,7 @@ export default function HeaderCell<R, SR>({
8585 direction,
8686 dragDropKey
8787} : HeaderCellProps < R , SR > ) {
88+ const hasDoubleClickedRef = useRef ( false ) ;
8889 const [ isDragging , setIsDragging ] = useState ( false ) ;
8990 const [ isOver , setIsOver ] = useState ( false ) ;
9091 const isRtl = direction === 'rtl' ;
@@ -119,7 +120,7 @@ export default function HeaderCell<R, SR>({
119120 const headerCell = currentTarget . parentElement ! ;
120121 const { right, left } = headerCell . getBoundingClientRect ( ) ;
121122 const offset = isRtl ? event . clientX - left : right - event . clientX ;
122- let hasDoubleClicked = false ;
123+ hasDoubleClickedRef . current = false ;
123124
124125 function onPointerMove ( event : PointerEvent ) {
125126 const { width, right, left } = headerCell . getBoundingClientRect ( ) ;
@@ -130,29 +131,27 @@ export default function HeaderCell<R, SR>({
130131 }
131132 }
132133
133- function onDoubleClick ( ) {
134- hasDoubleClicked = true ;
135- onColumnResize ( column , 'max-content' ) ;
136- }
137-
138134 function onLostPointerCapture ( event : PointerEvent ) {
139135 // Handle final pointer position that may have been skipped by coalesced pointer move events.
140136 // Skip move pointer handling if the user double-clicked.
141- if ( ! hasDoubleClicked ) {
137+ if ( ! hasDoubleClickedRef . current ) {
142138 onPointerMove ( event ) ;
143139 }
144140
145141 currentTarget . removeEventListener ( 'pointermove' , onPointerMove ) ;
146- currentTarget . removeEventListener ( 'dblclick' , onDoubleClick ) ;
147142 currentTarget . removeEventListener ( 'lostpointercapture' , onLostPointerCapture ) ;
148143 }
149144
150145 currentTarget . setPointerCapture ( pointerId ) ;
151146 currentTarget . addEventListener ( 'pointermove' , onPointerMove ) ;
152- currentTarget . addEventListener ( 'dblclick' , onDoubleClick ) ;
153147 currentTarget . addEventListener ( 'lostpointercapture' , onLostPointerCapture ) ;
154148 }
155149
150+ function onDoubleClick ( ) {
151+ hasDoubleClickedRef . current = true ;
152+ onColumnResize ( column , 'max-content' ) ;
153+ }
154+
156155 function onSort ( ctrlClick : boolean ) {
157156 if ( onSortColumnsChange == null ) return ;
158157 const { sortDescendingFirst } = column ;
@@ -304,6 +303,7 @@ export default function HeaderCell<R, SR>({
304303 className = { resizeHandleClassname }
305304 onClick = { stopPropagation }
306305 onPointerDown = { onPointerDown }
306+ onDoubleClick = { onDoubleClick }
307307 />
308308 ) }
309309 </ div >
0 commit comments