āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/udecode/plate/(plugins)/(functionality)/block-placeholder ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
The fastest way to add block placeholders is with the BlockPlaceholderKit, which includes the pre-configured BlockPlaceholderPlugin.
import { createPlateEditor } from 'platejs/react';
import { BlockPlaceholderKit } from '@/components/editor/plugins/block-placeholder-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...BlockPlaceholderKit,
],
});
</Steps>
Block placeholders are included in the core Plate package.
import { BlockPlaceholderPlugin } from 'platejs/react';
import { BlockPlaceholderPlugin } from 'platejs/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
BlockPlaceholderPlugin,
],
});
Configure placeholders for different block types:
import { KEYS } from 'platejs';
import { BlockPlaceholderPlugin } from 'platejs/react';
BlockPlaceholderPlugin.configure({
options: {
placeholders: {
[KEYS.p]: 'Type something...',
[KEYS.h1]: 'Enter heading...',
[KEYS.blockquote]: 'Enter quote...',
[KEYS.codeBlock]: 'Enter code...',
},
},
});
Customize appearance and visibility rules:
import { KEYS } from 'platejs';
import { BlockPlaceholderPlugin } from 'platejs/react';
BlockPlaceholderPlugin.configure({
options: {
className: 'before:absolute before:cursor-text before:opacity-30 before:content-[attr(placeholder)]',
placeholders: {
[KEYS.p]: 'Type something...',
},
query: ({ path }) => {
// Only show placeholders in root-level blocks
return path.length === 1;
},
},
});
placeholders: Map of block types to placeholder text.className: CSS classes applied to blocks with placeholders.query: Function to determine which blocks should show placeholders.BlockPlaceholderPluginPlugin for displaying placeholder text in empty blocks.
The plugin shows placeholders when all of these conditions are met:
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā