-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Use mouse down event to select cell #3774
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
Changes from all commits
95b949f
8c97e9c
1eda14b
93c798f
88fc2fe
b3d4ee2
991398b
61be870
bd7b2af
aab098f
2607555
ecf82e6
b80c74b
b02f1e2
eb0895a
2e7ad9c
4c4ee2c
c9290d8
3e43814
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,14 +40,13 @@ import { | |
} from './utils'; | ||
import type { | ||
CalculatedColumn, | ||
CellClickArgs, | ||
CellClipboardEvent, | ||
CellCopyEvent, | ||
CellCopyArgs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to match other types |
||
CellKeyboardEvent, | ||
CellKeyDownArgs, | ||
CellMouseEvent, | ||
CellMouseEventHandler, | ||
CellNavigationMode, | ||
CellPasteEvent, | ||
CellPasteArgs, | ||
CellSelectArgs, | ||
Column, | ||
ColumnOrColumnGroup, | ||
|
@@ -186,29 +185,25 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha | |
/** | ||
* Event props | ||
*/ | ||
/** Callback triggered when a pointer becomes active in a cell */ | ||
onCellMouseDown?: CellMouseEventHandler<R, SR>; | ||
/** Callback triggered when a cell is clicked */ | ||
onCellClick?: Maybe< | ||
(args: CellClickArgs<NoInfer<R>, NoInfer<SR>>, event: CellMouseEvent) => void | ||
>; | ||
onCellClick?: CellMouseEventHandler<R, SR>; | ||
/** Callback triggered when a cell is double-clicked */ | ||
onCellDoubleClick?: Maybe< | ||
(args: CellClickArgs<NoInfer<R>, NoInfer<SR>>, event: CellMouseEvent) => void | ||
>; | ||
onCellDoubleClick?: CellMouseEventHandler<R, SR>; | ||
/** Callback triggered when a cell is right-clicked */ | ||
onCellContextMenu?: Maybe< | ||
(args: CellClickArgs<NoInfer<R>, NoInfer<SR>>, event: CellMouseEvent) => void | ||
>; | ||
onCellContextMenu?: CellMouseEventHandler<R, SR>; | ||
/** Callback triggered when a key is pressed in a cell */ | ||
onCellKeyDown?: Maybe< | ||
(args: CellKeyDownArgs<NoInfer<R>, NoInfer<SR>>, event: CellKeyboardEvent) => void | ||
>; | ||
/** Callback triggered when a cell's content is copied */ | ||
onCellCopy?: Maybe< | ||
(args: CellCopyEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void | ||
(args: CellCopyArgs<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void | ||
>; | ||
/** Callback triggered when content is pasted into a cell */ | ||
onCellPaste?: Maybe< | ||
(args: CellPasteEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => NoInfer<R> | ||
(args: CellPasteArgs<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => NoInfer<R> | ||
>; | ||
/** Function called whenever cell selection is changed */ | ||
onSelectedCellChange?: Maybe<(args: CellSelectArgs<NoInfer<R>, NoInfer<SR>>) => void>; | ||
|
@@ -274,6 +269,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr | |
onSortColumnsChange, | ||
defaultColumnOptions, | ||
// Event props | ||
onCellMouseDown, | ||
onCellClick, | ||
onCellDoubleClick, | ||
onCellContextMenu, | ||
|
@@ -493,6 +489,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr | |
const handleColumnResizeEndLatest = useLatestFunc(handleColumnResizeEnd); | ||
const onColumnsReorderLastest = useLatestFunc(onColumnsReorder); | ||
const onSortColumnsChangeLatest = useLatestFunc(onSortColumnsChange); | ||
const onCellMouseDownLatest = useLatestFunc(onCellMouseDown); | ||
const onCellClickLatest = useLatestFunc(onCellClick); | ||
const onCellDoubleClickLatest = useLatestFunc(onCellDoubleClick); | ||
const onCellContextMenuLatest = useLatestFunc(onCellContextMenu); | ||
|
@@ -525,23 +522,17 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr | |
/** | ||
* effects | ||
*/ | ||
useLayoutEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This effect didn't depend on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This effect was not checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was it never running when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe so |
||
if ( | ||
focusSinkRef.current !== null && | ||
selectedCellIsWithinSelectionBounds && | ||
selectedPosition.idx === -1 | ||
) { | ||
focusSinkRef.current.focus({ preventScroll: true }); | ||
scrollIntoView(focusSinkRef.current); | ||
} | ||
}, [selectedCellIsWithinSelectionBounds, selectedPosition]); | ||
|
||
useLayoutEffect(() => { | ||
if (shouldFocusCell) { | ||
if (focusSinkRef.current !== null && selectedPosition.idx === -1) { | ||
focusSinkRef.current.focus({ preventScroll: true }); | ||
scrollIntoView(focusSinkRef.current); | ||
} else { | ||
focusCellOrCellContent(); | ||
} | ||
setShouldFocusCell(false); | ||
focusCellOrCellContent(); | ||
} | ||
}, [shouldFocusCell, focusCellOrCellContent]); | ||
}, [shouldFocusCell, focusCellOrCellContent, selectedPosition.idx]); | ||
|
||
useImperativeHandle(ref, () => ({ | ||
element: gridRef.current, | ||
|
@@ -1141,6 +1132,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr | |
viewportColumns: rowColumns, | ||
isRowSelectionDisabled: isRowSelectionDisabled?.(row) ?? false, | ||
isRowSelected, | ||
onCellMouseDown: onCellMouseDownLatest, | ||
onCellClick: onCellClickLatest, | ||
onCellDoubleClick: onCellDoubleClickLatest, | ||
onCellContextMenu: onCellContextMenuLatest, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onClick
andonContextMenu
events do not have any default behavior now but we are keeping the same signature as users may want to edit on single click or right click