Skip to content

Commit 66c6259

Browse files
committed
feat(placeholder): hide placeholder in atom nodes by default
1 parent a44a7c3 commit 66c6259

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.changeset/ten-cars-sparkle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tiptap/extension-placeholder": patch
3+
---
4+
5+
feat(placeholder): do not show placeholder on atom nodes by default

packages/extension-placeholder/src/placeholder.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ export interface PlaceholderOptions {
6363
* @default false
6464
*/
6565
includeChildren: boolean
66+
67+
/**
68+
* **Controls if the placeholder should be shown for atom nodes.**
69+
*
70+
* If true, the placeholder will be shown for atom nodes.
71+
* If false, the placeholder will not be shown for atom nodes.
72+
* @default false
73+
*/
74+
showWhenAtom: boolean;
6675
}
6776

6877
/**
@@ -81,6 +90,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
8190
showOnlyWhenEditable: true,
8291
showOnlyCurrent: true,
8392
includeChildren: false,
93+
showWhenAtom: false,
8494
}
8595
},
8696

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

107-
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
118+
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty && isContentEditable) {
108119
const classes = [this.options.emptyNodeClass]
109120

110121
if (isEmptyDoc) {

0 commit comments

Comments
 (0)