Skip to content

Commit

Permalink
Merge pull request #2724 from duckRabbitPy/duckrabbitpy-fix/2723
Browse files Browse the repository at this point in the history
handle new row header property
  • Loading branch information
zbeyens authored Nov 28, 2023
2 parents 22be03b + dd6a2a5 commit b687374
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .changeset/six-bears-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@udecode/plate-table": patch
---

Table row insertion: cells in a newly added row will now receive header styling only if they satisfy specific criteria:
- Every cell in the column is a header cell,
- The table contains more than one row, or
- The column possesses a predefined header property.
20 changes: 11 additions & 9 deletions packages/table/src/transforms/insertTableRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ export const insertTableRow = <V extends Value>(

const getEmptyRowNode = () => ({
type: getPluginType(editor, ELEMENT_TR),
children: (trNode.children as TElement[]).map((_, i) =>
getEmptyCellNode(editor, {
header:
header ??
(tableEntry[0].children as TElement[]).every(
(n) => n.children[i].type === ELEMENT_TH
),
children: (trNode.children as TElement[]).map((_, i) => {
const hasSingleRow = tableEntry[0].children.length === 1;
const isHeaderColumn =
!hasSingleRow &&
(tableEntry[0].children as TElement[]).every(
(n) => n.children[i].type === ELEMENT_TH
);
return getEmptyCellNode(editor, {
header: header ?? isHeaderColumn,
...newCellChildren,
})
),
});
}),
});

withoutNormalizing(editor, () => {
Expand Down

0 comments on commit b687374

Please sign in to comment.