diff --git a/.changeset/popular-cups-bake.md b/.changeset/popular-cups-bake.md new file mode 100644 index 0000000000..e3ed7b0f57 --- /dev/null +++ b/.changeset/popular-cups-bake.md @@ -0,0 +1,5 @@ +--- +"@udecode/plate-table": patch +--- + +canMerge = true only if user selected more than one cell diff --git a/packages/table/src/merge/useTableMergeState.ts b/packages/table/src/merge/useTableMergeState.ts index 0ff2f09776..c925a42681 100644 --- a/packages/table/src/merge/useTableMergeState.ts +++ b/packages/table/src/merge/useTableMergeState.ts @@ -12,7 +12,7 @@ import { getTableGridAbove } from '../queries'; import { getColSpan } from '../queries/getColSpan'; import { getRowSpan } from '../queries/getRowSpan'; import { useTableStore } from '../stores'; -import { TablePlugin } from '../types'; +import { TTableCellElement, TablePlugin } from '../types'; import { isTableRectangular } from './isTableRectangular'; export const useTableMergeState = () => { @@ -41,18 +41,20 @@ export const useTableMergeState = () => { [] ); + if (!selectedCellEntries) return { canMerge: false, canUnmerge: false }; + const canMerge = !readOnly && selected && selectionExpanded && + selectedCellEntries.length > 1 && isTableRectangular(selectedTable); const canUnmerge = collapsed && - selectedCellEntries && selectedCellEntries.length === 1 && - (getColSpan(selectedCellEntries[0][0] as any) > 1 || - getRowSpan(selectedCellEntries[0][0] as any) > 1); + (getColSpan(selectedCellEntries[0][0] as TTableCellElement) > 1 || + getRowSpan(selectedCellEntries[0][0] as TTableCellElement) > 1); return { canMerge, canUnmerge }; };