Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions src/HeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useRef, useState } from 'react';
import { css } from '@linaria/core';

import { useRovingTabIndex } from './hooks';
Expand Down Expand Up @@ -85,6 +85,7 @@ 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 @@ -119,7 +120,7 @@ export default function HeaderCell<R, SR>({
const headerCell = currentTarget.parentElement!;
const { right, left } = headerCell.getBoundingClientRect();
const offset = isRtl ? event.clientX - left : right - event.clientX;
let hasDoubleClicked = false;
hasDoubleClickedRef.current = false;

function onPointerMove(event: PointerEvent) {
const { width, right, left } = headerCell.getBoundingClientRect();
Expand All @@ -130,29 +131,27 @@ export default function HeaderCell<R, SR>({
}
}

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

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 (!hasDoubleClicked) {
if (!hasDoubleClickedRef.current) {
onPointerMove(event);
}

currentTarget.removeEventListener('pointermove', onPointerMove);
currentTarget.removeEventListener('dblclick', onDoubleClick);
currentTarget.removeEventListener('lostpointercapture', onLostPointerCapture);
}

currentTarget.setPointerCapture(pointerId);
currentTarget.addEventListener('pointermove', onPointerMove);
currentTarget.addEventListener('dblclick', onDoubleClick);
currentTarget.addEventListener('lostpointercapture', onLostPointerCapture);
}

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

function onSort(ctrlClick: boolean) {
if (onSortColumnsChange == null) return;
const { sortDescendingFirst } = column;
Expand Down Expand Up @@ -304,6 +303,7 @@ export default function HeaderCell<R, SR>({
className={resizeHandleClassname}
onClick={stopPropagation}
onPointerDown={onPointerDown}
onDoubleClick={onDoubleClick}
/>
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions test/browser/column/resizable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, userEvent } from '@vitest/browser/context';
import { commands, page } from '@vitest/browser/context';

import type { Column } from '../../../src';
import { resizeHandleClassname } from '../../../src/HeaderCell';
Expand Down Expand Up @@ -36,9 +36,9 @@ async function resize({ column, resizeBy }: ResizeArgs) {
}

async function autoResize(column: Element) {
const resizeHandle = getResizeHandle(column);
const resizeHandle = page.elementLocator(getResizeHandle(column));

await userEvent.dblClick(resizeHandle);
await resizeHandle.dblClick();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to see if the order of events would reflect actual browser behavior, as userEvent does not perform real browser/cursor actions.

}

const columns: readonly Column<Row>[] = [
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.website.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"]
"lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"],
"skipLibCheck": true
},
"include": ["website/**/*"],
"references": [{ "path": "tsconfig.src.json" }]
Expand Down