From c03253de7f74d5a674647359a8b297e2a37d476e Mon Sep 17 00:00:00 2001 From: Deniz97 Date: Fri, 22 Mar 2024 15:39:36 +0300 Subject: [PATCH] chore: add props option for smart delete feature --- src/components/DataSheetGrid.tsx | 4 +++- src/types.ts | 1 + website/docs/api-reference/props.mdx | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/DataSheetGrid.tsx b/src/components/DataSheetGrid.tsx index cd3aa070..e604e354 100644 --- a/src/components/DataSheetGrid.tsx +++ b/src/components/DataSheetGrid.tsx @@ -77,6 +77,7 @@ export const DataSheetGrid = React.memo( autoAddRow = false, lockRows = false, disableExpandSelection = false, + disableSmartDelete = false, duplicateRow = DEFAULT_DUPLICATE_ROW, contextMenuComponent: ContextMenuComponent = ContextMenu, disableContextMenu: disableContextMenuRaw = false, @@ -513,7 +514,8 @@ export const DataSheetGrid = React.memo( ) const deleteSelection = useCallback( - (smartDelete = true) => { + (_smartDelete = true) => { + const smartDelete = _smartDelete && !disableSmartDelete if (!activeCell) { return } diff --git a/src/types.ts b/src/types.ts index 768ec556..7e5adb92 100644 --- a/src/types.ts +++ b/src/types.ts @@ -148,6 +148,7 @@ export type DataSheetGridProps = { lockRows?: boolean disableContextMenu?: boolean disableExpandSelection?: boolean + disableSmartDelete?: boolean contextMenuComponent?: ( props: ContextMenuComponentProps ) => React.ReactElement | null diff --git a/website/docs/api-reference/props.mdx b/website/docs/api-reference/props.mdx index c11b9fd0..40267dd8 100644 --- a/website/docs/api-reference/props.mdx +++ b/website/docs/api-reference/props.mdx @@ -178,6 +178,12 @@ When true, no context menu is shown when right clicking. `disableContextMenu` is When true, the user will not be able to drag the corner of the selection to expand it. +### disableSmartDelete +> Type: `boolean`
+> Default: `false` + +When false, deleting an empty cell will select the whole row, and deleting an empty cell of an empty row will actually remove the row from the sheet. Second behaviour is auto-disabled if the lockRows option is enabled. + ## Style ### className > Type: `string`