2021-10-14 06:13:50 +08:00
---
description: Configure a helpful placeholder to fill the emptyness.
2021-10-16 04:48:57 +08:00
icon: ghost-line
2021-10-14 06:13:50 +08:00
---
2021-03-25 05:50:30 +08:00
# Placeholder
[![Version ](https://img.shields.io/npm/v/@tiptap/extension-placeholder.svg?label=version )](https://www.npmjs.com/package/@tiptap/extension-placeholder)
[![Downloads ](https://img.shields.io/npm/dm/@tiptap/extension-placeholder.svg )](https://npmcharts.com/compare/@tiptap/extension-placeholder?minimal=true)
2021-03-31 02:45:48 +08:00
This extension provides placeholder support. Give your users an idea what they should write with a tiny hint. There is a handful of things to customize, if you feel like it.
2021-03-25 05:50:30 +08:00
## Installation
```bash
npm install @tiptap/extension -placeholder
```
2023-02-07 17:07:50 +08:00
### Additional Setup
Placeholders are displayed with the help of CSS.
**Display a Placeholder only for the first line in an empty editor.**
```
2023-05-25 19:45:06 +08:00
.tiptap p.is-editor-empty:first-child::before {
2023-02-07 17:07:50 +08:00
color: #adb5bd ;
content: attr(data-placeholder);
float: left;
height: 0;
pointer-events: none;
}
```
**Display Placeholders on every new line.**
```
2023-05-25 19:45:06 +08:00
.tiptap p.is-empty::before {
2023-02-07 17:07:50 +08:00
color: #adb5bd ;
content: attr(data-placeholder);
float: left;
height: 0;
pointer-events: none;
}
```
2021-03-25 05:50:30 +08:00
## Settings
2021-10-02 07:20:09 +08:00
### emptyEditorClass
The added CSS class if the editor is empty.
Default: `'is-editor-empty'`
```js
Placeholder.configure({
emptyEditorClass: 'is-editor-empty',
})
```
### emptyNodeClass
The added CSS class if the node is empty.
Default: `'is-empty'`
```js
Placeholder.configure({
emptyNodeClass: 'my-custom-is-empty-class',
})
```
### placeholder
The placeholder text added as `data-placeholder` attribute.
Default: `'Write something …'`
```js
Placeholder.configure({
placeholder: 'My Custom Placeholder',
})
```
You can even use a function to add placeholder depending on the node:
```js
Placeholder.configure({
placeholder: ({ node }) => {
if (node.type.name === 'heading') {
return 'What’ s the title?'
}
return 'Can you add some further context?'
},
})
```
2023-08-19 01:52:33 +08:00
### considerAnyAsEmpty
Consider any node that is not a leaf or atom as empty for the editor empty check.
Default: `false`
```js
Placeholder.configure({
considerAnyAsEmpty: true,
})
```
2021-10-02 07:20:09 +08:00
### showOnlyWhenEditable
Show decorations only when editor is editable.
Default: `true`
```js
Placeholder.configure({
showOnlyWhenEditable: false,
})
```
### showOnlyCurrent
Show decorations only in currently selected node.
Default: `true`
```js
Placeholder.configure({
showOnlyCurrent: false
})
```
2021-11-12 16:20:50 +08:00
### includeChildren
Show decorations also for nested nodes.
Default: `false`
```js
Placeholder.configure({
includeChildren: true
})
```
2021-03-25 05:50:30 +08:00
## Source code
2021-04-21 21:31:11 +08:00
[packages/extension-placeholder/ ](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-placeholder/ )
2021-03-25 05:50:30 +08:00
## Usage
2021-10-19 00:01:47 +08:00
https://embed.tiptap.dev/preview/Extensions/Placeholder