Skip to content

Commit

Permalink
feat: add onGridFocused()/onGridBlurred() callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSisb committed Jul 31, 2024
1 parent 63f708d commit 7f90cb4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
6 changes: 4 additions & 2 deletions dist/cjs/data-editor/data-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cjs/data-editor/data-editor.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/dts/data-editor-all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export interface DataEditorAllProps extends Omit<DataEditorProps, "renderers" |
imageWindowLoader?: ImageWindowLoader;
}
export declare const DataEditorAll: React.ForwardRefExoticComponent<DataEditorAllProps & React.RefAttributes<DataEditorRef>>;
//# sourceMappingURL=data-editor-all.d.ts.map
9 changes: 8 additions & 1 deletion dist/dts/data-editor/data-editor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export interface DataEditorProps extends Props, Pick<DataGridSearchProps, "image
* @group Events
*/
readonly onCellActivated?: (cell: Item) => void;
/** Emitted when the grid is focused.
* @group Events
*/
readonly onGridFocused?: () => void;
/** Emitted when the grid is blurred.
* @group Events
*/
readonly onGridBlurred?: () => void;
/**
* Emitted whenever the user initiats a pattern fill using the fill handle. This event provides both
* a patternSource region and a fillDestination region, and can be prevented.
Expand Down Expand Up @@ -501,4 +509,3 @@ export interface DataEditorRef {
*/
export declare const DataEditor: React.ForwardRefExoticComponent<DataEditorProps & React.RefAttributes<DataEditorRef>>;
export {};
//# sourceMappingURL=data-editor.d.ts.map
2 changes: 1 addition & 1 deletion dist/dts/data-editor/data-editor.d.ts.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions dist/esm/data-editor/data-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/esm/data-editor/data-editor.js.map

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ export interface DataEditorProps extends Props, Pick<DataGridSearchProps, "image
* @group Events
*/
readonly onCellActivated?: (cell: Item) => void;
/** Emitted when the grid is focused.
* @group Events
*/
readonly onGridFocused?: () => void;
/** Emitted when the grid is blurred.
* @group Events
*/
readonly onGridBlurred?: () => void;

/**
* Emitted whenever the user initiats a pattern fill using the fill handle. This event provides both
Expand Down Expand Up @@ -765,6 +773,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
getCellContent,
onCellClicked,
onCellActivated,
onGridFocused,
onGridBlurred,
onFillPattern,
onFinishedEditing,
coercePasteValue,
Expand Down Expand Up @@ -3943,12 +3953,12 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
const setIsFocusedDebounced = React.useRef(
debounce((val: boolean) => {
setIsFocused(val);
onGridFocused?.();
}, 5)
);

const onCanvasFocused = React.useCallback(() => {
setIsFocusedDebounced.current(true);

// check for mouse state, don't do anything if the user is clicked to focus.
if (
gridSelection.current === undefined &&
Expand All @@ -3975,7 +3985,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr

const onFocusOut = React.useCallback(() => {
setIsFocusedDebounced.current(false);
}, []);
onGridBlurred?.();
}, [onGridBlurred]);

const [idealWidth, idealHeight] = React.useMemo(() => {
let h: number;
Expand Down

0 comments on commit 7f90cb4

Please sign in to comment.