-
Notifications
You must be signed in to change notification settings - Fork 406
feat: add onKeyDown event on custom cell renderer #1156
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -3498,6 +3498,45 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr | |
|
|
||
| if (cancelled) return; | ||
|
|
||
| if (event.location !== undefined && event.bounds !== undefined && !overlayOpen) { | ||
| const [col, row] = event.location; | ||
| const cell = getMangledCellContent([col, row]); | ||
| const renderer = getCellRenderer(cell); | ||
|
|
||
| if (renderer?.onKeyDown !== undefined) { | ||
| let prevented = false; | ||
| const newVal = renderer.onKeyDown({ | ||
| ...event, | ||
| bounds: event.bounds, | ||
| cell, | ||
| location: [col - rowMarkerOffset, row], | ||
|
||
| theme: themeForCell(cell, event.location), | ||
| preventDefault: () => { | ||
| prevented = true; | ||
| }, | ||
| }); | ||
|
|
||
| if (prevented) { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| } | ||
|
|
||
| if ( | ||
| newVal !== undefined && | ||
| !isInnerOnlyCell(newVal) && | ||
| isEditableGridCell(newVal) && | ||
| !isInnerOnlyCell(cell) && | ||
| isEditableGridCell(cell) && | ||
| cell.readonly !== true | ||
| ) { | ||
| mangledOnCellsEdited([{ location: event.location, value: newVal }]); | ||
| gridRef.current?.damage([{ cell: event.location }]); | ||
| } | ||
|
|
||
| if (prevented) return; | ||
| } | ||
| } | ||
|
|
||
| if (handleFixedKeybindings(event)) return; | ||
|
|
||
| if (gridSelection.current === undefined) return; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
boundsis manually given because bounds is required prop in onKeyDown and TS doesn't understand that bounds is always defined from...event.