Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Table renders with invalid minWidth CSS property in the style attribute #5217

Closed
1 task done
matthewfinger opened this issue Jun 11, 2024 · 3 comments
Closed
1 task done
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@matthewfinger
Copy link

Affected Packages

extension-table

Version(s)

2.4.0

Bug Description

If I use the minimal table configuration, with just Table, TableHeader, TableRow, TableCell added to the extensions array, tables without a minimum cell/col width end up having style: `minWidth: ${tableMinWidth}`, added to the attributes, however this should be min-width.

It's pretty simple, I can see the issue right here https://github.com/ueberdosis/tiptap/blob/bd480a20097ee4522a250b1bc03e8779f014818e/packages/extension-table/src/table.ts#L289C26-L289C39

Looks like there was a PR with a fix that was recently closed by the author: #4684 instead of getting merged in.

Browser Used

Chrome

Code Example URL

https://codesandbox.io/p/sandbox/icy-dust-tgrzdd?file=%2Fsrc%2Findex.js%3A7%2C54

Expected Behavior

When a table is inserted, it should have min-width in the style attribute.

Additional Context (Optional)

No response

Dependency Updates

  • Yes, I've updated all my dependencies.
@matthewfinger matthewfinger added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Jun 11, 2024
@github-project-automation github-project-automation bot moved this to Triage open in Tiptap Jun 11, 2024
@zhondori
Copy link

I also encounter this issue which is technically very easy to fix and just CSS typo in table extension code

@Ragnar-Oock
Copy link
Contributor

Ragnar-Oock commented Jul 24, 2024

while waiting for this issue to be resolved you can simply extend the base table extension like so :

import { Table } from '@tiptap/extension-table';

export const CorrectedTable = Table.extend({
	renderHTML(props) {
		const tableNode = this.parent(props);
		tableNode[1].style = tableNode[1].style?.replace('minWidth', 'min-width');
		return tableNode;
	},
});

Or you could copy paste the implementation of renderHTML from @tiptap/extension-table like so. But that means you have to maintain it yourself.

import { Table } from '@tiptap/extension-table';

export const CorrectedTable = Table.extend({
	renderHTML({ node, HTMLAttributes }) {
		const {
			colgroup, tableWidth, tableMinWidth
		} = createColGroup(
			node,
			this.options.cellMinWidth,
		);

		const table: DOMOutputSpec = [
			'table',
			mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
				style: tableWidth
					? `width: ${ tableWidth }`
					: `min-width: ${ tableMinWidth }`, // this is the line that changed
			}),
			colgroup,
			[ 'tbody', 0 ],
		];

		return table;
	},
});

@nperez0111
Copy link

This will be fixed in the next version, I just merged in that closed PR

@github-project-automation github-project-automation bot moved this from Triage open to Done in Tiptap Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
No open projects
Archived in project
Development

No branches or pull requests

4 participants