1
- import { useState } from 'react' ;
1
+ import { useRef , useState } from 'react' ;
2
2
import { css } from '@linaria/core' ;
3
3
4
4
import { useRovingTabIndex } from './hooks' ;
@@ -85,6 +85,7 @@ export default function HeaderCell<R, SR>({
85
85
direction,
86
86
dragDropKey
87
87
} : HeaderCellProps < R , SR > ) {
88
+ const hasDoubleClickedRef = useRef ( false ) ;
88
89
const [ isDragging , setIsDragging ] = useState ( false ) ;
89
90
const [ isOver , setIsOver ] = useState ( false ) ;
90
91
const isRtl = direction === 'rtl' ;
@@ -119,7 +120,7 @@ export default function HeaderCell<R, SR>({
119
120
const headerCell = currentTarget . parentElement ! ;
120
121
const { right, left } = headerCell . getBoundingClientRect ( ) ;
121
122
const offset = isRtl ? event . clientX - left : right - event . clientX ;
122
- let hasDoubleClicked = false ;
123
+ hasDoubleClickedRef . current = false ;
123
124
124
125
function onPointerMove ( event : PointerEvent ) {
125
126
const { width, right, left } = headerCell . getBoundingClientRect ( ) ;
@@ -130,29 +131,27 @@ export default function HeaderCell<R, SR>({
130
131
}
131
132
}
132
133
133
- function onDoubleClick ( ) {
134
- hasDoubleClicked = true ;
135
- onColumnResize ( column , 'max-content' ) ;
136
- }
137
-
138
134
function onLostPointerCapture ( event : PointerEvent ) {
139
135
// Handle final pointer position that may have been skipped by coalesced pointer move events.
140
136
// Skip move pointer handling if the user double-clicked.
141
- if ( ! hasDoubleClicked ) {
137
+ if ( ! hasDoubleClickedRef . current ) {
142
138
onPointerMove ( event ) ;
143
139
}
144
140
145
141
currentTarget . removeEventListener ( 'pointermove' , onPointerMove ) ;
146
- currentTarget . removeEventListener ( 'dblclick' , onDoubleClick ) ;
147
142
currentTarget . removeEventListener ( 'lostpointercapture' , onLostPointerCapture ) ;
148
143
}
149
144
150
145
currentTarget . setPointerCapture ( pointerId ) ;
151
146
currentTarget . addEventListener ( 'pointermove' , onPointerMove ) ;
152
- currentTarget . addEventListener ( 'dblclick' , onDoubleClick ) ;
153
147
currentTarget . addEventListener ( 'lostpointercapture' , onLostPointerCapture ) ;
154
148
}
155
149
150
+ function onDoubleClick ( ) {
151
+ hasDoubleClickedRef . current = true ;
152
+ onColumnResize ( column , 'max-content' ) ;
153
+ }
154
+
156
155
function onSort ( ctrlClick : boolean ) {
157
156
if ( onSortColumnsChange == null ) return ;
158
157
const { sortDescendingFirst } = column ;
@@ -304,6 +303,7 @@ export default function HeaderCell<R, SR>({
304
303
className = { resizeHandleClassname }
305
304
onClick = { stopPropagation }
306
305
onPointerDown = { onPointerDown }
306
+ onDoubleClick = { onDoubleClick }
307
307
/>
308
308
) }
309
309
</ div >
0 commit comments