Skip to content

Commit

Permalink
Merge pull request #3034 from KorovinQuantori/main
Browse files Browse the repository at this point in the history
Check user selection on useTableMergeState
  • Loading branch information
zbeyens authored Mar 20, 2024
2 parents e322560 + 96cf1f0 commit 6eda8a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-cups-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-table": patch
---

canMerge = true only if user selected more than one cell
10 changes: 6 additions & 4 deletions packages/table/src/merge/useTableMergeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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 };
};

0 comments on commit 6eda8a5

Please sign in to comment.