Skip to content

Commit

Permalink
feat(placeholder): hide placeholder in atom nodes by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadiBlitz committed Jan 21, 2025
1 parent a44a7c3 commit 66c6259
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/ten-cars-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/extension-placeholder": patch
---

feat(placeholder): do not show placeholder on atom nodes by default
13 changes: 12 additions & 1 deletion packages/extension-placeholder/src/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export interface PlaceholderOptions {
* @default false
*/
includeChildren: boolean

/**
* **Controls if the placeholder should be shown for atom nodes.**
*
* If true, the placeholder will be shown for atom nodes.
* If false, the placeholder will not be shown for atom nodes.
* @default false
*/
showWhenAtom: boolean;
}

/**
Expand All @@ -81,6 +90,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
showOnlyWhenEditable: true,
showOnlyCurrent: true,
includeChildren: false,
showWhenAtom: false,
}
},

Expand All @@ -103,8 +113,9 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
doc.descendants((node, pos) => {
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize
const isEmpty = !node.isLeaf && isNodeEmpty(node)
const isContentEditable = this.options.showWhenAtom ? !node.type.isAtom : true;

if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty && isContentEditable) {
const classes = [this.options.emptyNodeClass]

if (isEmptyDoc) {
Expand Down

0 comments on commit 66c6259

Please sign in to comment.