Skip to content

Commit

Permalink
Merge pull request #1 from aramvr/fix-grid-hover-from-external-elements
Browse files Browse the repository at this point in the history
fix: grid is being hovered from an upper dialog
  • Loading branch information
citizensas committed Mar 27, 2023
2 parents c9e1f3d + 7cc985c commit 0ac43a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,16 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,

const hoveredRef = React.useRef<GridMouseEventArgs>();
const onMouseMoveImpl = React.useCallback(
(ev: MouseEvent) => {
(ev: MouseEvent) => {

const canvas = ref.current;
if (canvas === null) return;
const eventTarget = eventTargetRef?.current;



if (canvas === null || (ev.target !== canvas && ev.target !== eventTarget)) {
return;
}

const args = getMouseArgsForPosition(canvas, ev.clientX, ev.clientY, ev);
if (!isSameItem(args, hoveredRef.current)) {
Expand Down
24 changes: 24 additions & 0 deletions packages/core/test/data-grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,30 @@ describe("data-grid", () => {
);
});

test("Cell is not hovered when target is not data grid", () => {
const spy = jest.fn();

render(
<>
<DataGrid {...basicProps} onItemHovered={spy} />
<div data-testid="outside-element" style={{
position: 'absolute',
width: '100vh',
height: '100vh',
}} />
</>
);


const outsideElement = screen.getByTestId('outside-element');
fireEvent.mouseMove(outsideElement, {
clientX: 350, // Col C
clientY: 36 + 32 * 5 + 16, // Row 5 (0 indexed)
});

expect(spy).not.toHaveBeenCalled()
});

test("Header hovered", () => {
const spy = jest.fn();

Expand Down

0 comments on commit 0ac43a4

Please sign in to comment.