Skip to content

Commit 58b38d3

Browse files
authored
Merge branch 'main' into am-double-double-click
2 parents 0bc54d9 + 2c26504 commit 58b38d3

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/HeaderCell.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, useState } from 'react';
1+
import { useState } from 'react';
22
import { css } from '@linaria/core';
33

44
import { useRovingTabIndex } from './hooks';
@@ -85,7 +85,6 @@ export default function HeaderCell<R, SR>({
8585
direction,
8686
dragDropKey
8787
}: HeaderCellProps<R, SR>) {
88-
const hasDoubleClickedRef = useRef(false);
8988
const [isDragging, setIsDragging] = useState(false);
9089
const [isOver, setIsOver] = useState(false);
9190
const isRtl = direction === 'rtl';
@@ -120,8 +119,6 @@ export default function HeaderCell<R, SR>({
120119
const headerCell = currentTarget.parentElement!;
121120
const { right, left } = headerCell.getBoundingClientRect();
122121
const offset = isRtl ? event.clientX - left : right - event.clientX;
123-
hasDoubleClickedRef.current = false;
124-
125122
function onPointerMove(event: PointerEvent) {
126123
const { width, right, left } = headerCell.getBoundingClientRect();
127124
let newWidth = isRtl ? right + offset - event.clientX : event.clientX + offset - left;
@@ -131,24 +128,19 @@ export default function HeaderCell<R, SR>({
131128
}
132129
}
133130

134-
function onLostPointerCapture(event: PointerEvent) {
135-
// Handle final pointer position that may have been skipped by coalesced pointer move events.
136-
// Skip move pointer handling if the user double-clicked.
137-
if (!hasDoubleClickedRef.current) {
138-
onPointerMove(event);
139-
}
140-
131+
function onLostPointerCapture() {
141132
currentTarget.removeEventListener('pointermove', onPointerMove);
142133
currentTarget.removeEventListener('lostpointercapture', onLostPointerCapture);
143134
}
144135

145136
currentTarget.setPointerCapture(pointerId);
146137
currentTarget.addEventListener('pointermove', onPointerMove);
138+
// we are not using pointerup because it does not fire in some cases
139+
// pointer down -> alt+tab -> pointer up over another window -> pointerup event not fired
147140
currentTarget.addEventListener('lostpointercapture', onLostPointerCapture);
148141
}
149142

150143
function onDoubleClick() {
151-
hasDoubleClickedRef.current = true;
152144
onColumnResize(column, 'max-content');
153145
}
154146

0 commit comments

Comments
 (0)