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

feat(placeholder): hide placeholder in atom nodes by default #6044

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with making this an option, people should not have to care. You can also just disable the placeholder with css so I don't see why we would need to even modify the JS here

}

/**
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This var name doesn't really describe it well

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the atom is not considered a leaf? That is surprising to me? And it also isn't empty? That sounds wrong to me

Either the isNodeEmpty should be updated to make it be counted as being empty or something else is up here


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

if (isEmptyDoc) {
Expand Down