Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/HeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from 'react';
import { useState } from 'react';
import { css } from '@linaria/core';

import { useRovingTabIndex } from './hooks';
Expand Down Expand Up @@ -85,7 +85,6 @@ export default function HeaderCell<R, SR>({
direction,
dragDropKey
}: HeaderCellProps<R, SR>) {
const hasDoubleClickedRef = useRef(false);
const [isDragging, setIsDragging] = useState(false);
const [isOver, setIsOver] = useState(false);
const isRtl = direction === 'rtl';
Expand Down Expand Up @@ -120,8 +119,6 @@ export default function HeaderCell<R, SR>({
const headerCell = currentTarget.parentElement!;
const { right, left } = headerCell.getBoundingClientRect();
const offset = isRtl ? event.clientX - left : right - event.clientX;
hasDoubleClickedRef.current = false;

function onPointerMove(event: PointerEvent) {
const { width, right, left } = headerCell.getBoundingClientRect();
let newWidth = isRtl ? right + offset - event.clientX : event.clientX + offset - left;
Expand All @@ -131,24 +128,19 @@ export default function HeaderCell<R, SR>({
}
}

function onLostPointerCapture(event: PointerEvent) {
// Handle final pointer position that may have been skipped by coalesced pointer move events.
// Skip move pointer handling if the user double-clicked.
if (!hasDoubleClickedRef.current) {
onPointerMove(event);
}

function onLostPointerCapture() {
currentTarget.removeEventListener('pointermove', onPointerMove);
currentTarget.removeEventListener('lostpointercapture', onLostPointerCapture);
}

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

function onDoubleClick() {
hasDoubleClickedRef.current = true;
onColumnResize(column, 'max-content');
}

Expand Down