diff --git a/.changeset/six-bears-destroy.md b/.changeset/six-bears-destroy.md new file mode 100644 index 0000000000..d3bbd187a2 --- /dev/null +++ b/.changeset/six-bears-destroy.md @@ -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. diff --git a/packages/table/src/transforms/insertTableRow.ts b/packages/table/src/transforms/insertTableRow.ts index 575543feb8..3e520d0093 100644 --- a/packages/table/src/transforms/insertTableRow.ts +++ b/packages/table/src/transforms/insertTableRow.ts @@ -65,16 +65,18 @@ export const insertTableRow = ( 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, () => {