Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: manage direction of hover when grid table smaller than grid #811

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/core/src/data-grid/data-grid-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export interface GridMouseOutOfBoundsEventArgs extends BaseGridMouseEventArgs {
readonly location: Item;
readonly direction: readonly [-1 | 0 | 1, -1 | 0 | 1];
readonly isMaybeScrollbar: boolean;
readonly innerDirection: readonly [-1 | 0 | 1, -1 | 0 | 1];
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been thinking about this and I just don't like the name. Do you have any other suggestions to help us find a better name?

}

/** @category Types */
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
const horizontal = x > width ? -1 : x < 0 ? 1 : 0;
const vertical = y > height ? 1 : y < 0 ? -1 : 0;

let innerHorizontal: -1 | 0 | 1 = horizontal;
let innerVertical: -1 | 0 | 1 = vertical;
if (horizontal === 0 && vertical === 0) {
innerHorizontal = col === -1 ? -1 : 0;
innerVertical = row === undefined? 1 : 0;
}

let isEdge = false;
if (col === -1 && row === -1) {
const b = getBoundsForItem(canvas, mappedColumns.length - 1, -1);
Expand All @@ -527,6 +534,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
kind: outOfBoundsKind,
location: [col !== -1 ? col : x < 0 ? 0 : mappedColumns.length - 1, row ?? rows - 1],
direction: [horizontal, vertical],
innerDirection: [innerHorizontal, innerVertical],
shiftKey,
ctrlKey,
metaKey,
Expand Down Expand Up @@ -626,6 +634,19 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,

function isSameItem(item: GridMouseEventArgs | undefined, other: GridMouseEventArgs | undefined) {
if (item === other) return true;

if (item?.kind === "out-of-bounds") {
return (
item?.kind === other?.kind &&
item?.location[0] === other?.location[0] &&
item?.location[1] === other?.location[1] &&
item?.direction[0] === other?.direction[0] &&
item?.direction[1] === other?.direction[1] &&
item?.innerDirection[0] === other?.innerDirection[0] &&
item?.innerDirection[1] === other?.innerDirection[1]
);
}

return (
item?.kind === other?.kind &&
item?.location[0] === other?.location[0] &&
Expand Down
Loading