Skip to content

Add defaultStyle to a TipTap text block - #6384

Draft
VPS-Andreas wants to merge 3 commits into
tiptap-text-block-stylesfrom
tiptap-text-block-default-style
Draft

VPS-Andreas wants to merge 3 commits into
tiptap-text-block-stylesfrom
tiptap-text-block-default-style

Conversation

@VPS-Andreas

@VPS-Andreas VPS-Andreas commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

The styling select always offered a "Default" entry standing for "no style", even where a design has no unstyled variant and every paragraph or heading is meant to carry one of the configured styles. Editors had to pick the right style by hand on every new paragraph, and forgetting it produced unstyled content.

A text block (or list) with a defaultStyle has no such state:

createTipTapRichTextBlock({
    textBlocks: [
        { name: "heading-1", label: "Heading 1", tag: "h1", styles: headlineStyles, defaultStyle: "headline300" },
        { name: "heading-2", label: "Heading 2", tag: "h2", styles: headlineStyles, defaultStyle: "headline400" },
    ],
});

The select drops its "Default" entry, and the style is applied to new content and to every paragraph or heading the editor creates without one — pressing Enter at the end of a heading, the Mod-Alt-<level> shortcuts, pasting. Rather than reimplementing each of those paths, a ProseMirror plugin fills in a missing style on document change, so opening older content leaves it untouched and does not mark the document as changed. Switching the type keeps a style the new text block also offers and falls back to its defaultStyle otherwise, and toggling a list hands the paragraph to the list's styles or back — through the toolbar buttons and Mod-Shift-7/Mod-Shift-8 alike.

Because the default sits on the text block rather than on a tag, two text blocks sharing a tag can have different defaults, and a text block without one keeps its "Default" entry next to text blocks that have one. buildApplyTextBlocksMigration gives existing content its style up front and replaces a style a text block no longer offers.

Third of four stacked pull requests, on top of #6383 and #6382; #6385 splits the block's Storybook stories by topic.

Example

createTipTapRichTextBlock.test.ts/.test.tsx cover the validation and the migration. The Storybook story Default Text Block Style walks through a text block with a default, one without, and the styled lists.

Session: https://claude.ai/code/session_f3c6ad37-c68b-4187-85b6-2abe5aa95c35

@VPS-Obi

VPS-Obi commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

We'll review this once #6383 has been merged.

@VPS-Obi
VPS-Obi marked this pull request as draft September 17, 2026 07:52
@VPS-Obi
VPS-Obi removed request for VPS-Obi and nsams September 17, 2026 07:58
@VPS-Andreas
VPS-Andreas force-pushed the tiptap-text-block-default-style branch 2 times, most recently from 3ac786e to 7695789 Compare September 17, 2026 08:36
@VPS-Andreas
VPS-Andreas force-pushed the tiptap-text-block-default-style branch from 7695789 to 709b81b Compare September 17, 2026 09:08
VPS-Andreas and others added 3 commits September 17, 2026 11:20
The styling select always offered a "Default" entry standing for "no style", even
where a design has no unstyled variant. A text block with a defaultStyle drops
that entry, so every paragraph or heading of that type carries one of its styles.

The editor creates text blocks in several ways that don't go through the toolbar,
so a ProseMirror plugin fills the style in for any node that has none, rather
than reimplementing Enter, the keyboard shortcuts and paste one by one. It runs
only on a document change, so opening older content leaves it untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Toggling a list through the toolbar hands the cursor's paragraph from its text
block to the list or back, so the styles of whichever now holds it apply.
Mod-Shift-7 and Mod-Shift-8 went through the list extensions' own shortcuts and
left the previous style in place, which the list may not offer at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@VPS-Andreas
VPS-Andreas force-pushed the tiptap-text-block-default-style branch from 709b81b to 07ba087 Compare September 17, 2026 09:26
@VPS-Andreas
VPS-Andreas marked this pull request as ready for review September 17, 2026 10:00
@github-actions
github-actions Bot requested a review from VPS-Obi September 17, 2026 10:00
@VPS-Andreas
VPS-Andreas marked this pull request as draft September 17, 2026 10:00
@VPS-Obi
VPS-Obi removed their request for review September 17, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants