Placeholder Plugin
- Features
- showPlaceholder
- useInputsPlaceholder
- placeholder
- Basic Usage
- Use Textarea Placeholder
- Custom Placeholder
- Disable Placeholder
- RTL Language Support
- Listen to Placeholder Changes
- Initialization
- Placeholder Text Priority
- Empty Detection
- Show/Hide Logic
- Style Adaptation
- Event Triggers
- Debouncing
- RTL Support
- placeholder
- readonly
- Edge Cases
- Notes
- Typical Use Case
- Classes
Displays a placeholder text inside the editor when it's empty, similar to standard textarea placeholder behavior. The placeholder automatically shows/hides based on editor content and adapts its positioning and styling to match the editor's first element.
Features
- Automatic show/hide based on editor content
- Uses original textarea placeholder if available
- Customizable placeholder text
- RTL (right-to-left) language support
- Style matching with first editor element
- Position and padding adaptation
- Read-only mode handling
- Mode-aware (WYSIWYG only)
- Debounced toggle for performance
- Event-driven updates
showPlaceholder
Type: boolean
Default: true
When true, enables placeholder display in empty editor. When false, placeholder feature is completely disabled.
Example:
const editor = Jodit.make('#editor', {
showPlaceholder: true
});
useInputsPlaceholder
Type: boolean
Default: true
When true, uses the placeholder attribute from the original textarea/input element if it was set. When false, only uses the placeholder configuration option.
Example:
<textarea id="editor" placeholder="Enter your content here..."></textarea>
<script>
const editor = Jodit.make('#editor', {
useInputsPlaceholder: true // Will use "Enter your content here..."
});
</script>
placeholder
Type: string
Default: 'Type something'
Default placeholder text to display. Can be overridden by original element's placeholder attribute if useInputsPlaceholder is true.
Example:
const editor = Jodit.make('#editor', {
placeholder: 'Start typing your content...'
});
Basic Usage
const editor = Jodit.make('#editor', {
showPlaceholder: true,
placeholder: 'Type something'
});
Use Textarea Placeholder
<textarea id="editor" placeholder="Write your story here..."></textarea>
<script>
Jodit.make('#editor', {
showPlaceholder: true,
useInputsPlaceholder: true
});
</script>
Custom Placeholder
const editor = Jodit.make('#editor', {
showPlaceholder: true,
useInputsPlaceholder: false,
placeholder: 'Start typing your document...'
});
Disable Placeholder
const editor = Jodit.make('#editor', {
showPlaceholder: false
});
RTL Language Support
const editor = Jodit.make('#editor', {
showPlaceholder: true,
placeholder: 'ابدأ الكتابة هنا...',
direction: 'rtl'
});
Listen to Placeholder Changes
const editor = Jodit.make('#editor', {
showPlaceholder: true,
placeholder: 'Type something'
});
editor.e.on('placeholder', (text) => {
console.log('Placeholder text:', text);
});
Initialization
- Check Enabled: Exits if
showPlaceholderisfalse - Create Element: Creates
<span>with classjodit-placeholder - Set Text: Uses localized placeholder text
- RTL Handling: Sets
right: 0pxanddirection: rtlif editor is RTL - Event Setup: Registers event listeners for content changes
Placeholder Text Priority
The plugin determines placeholder text in this order:
- Original element's
placeholderattribute (ifuseInputsPlaceholderistrue) placeholderconfiguration option- Localized via
i18n()
Empty Detection
The isEditorEmpty() function checks if editor is empty:
- No Children: Returns
trueif no first child - Inseparable Tags: Returns
falseif first child is media element (img, video, etc.) - Tables: Returns
falseif first child is table - Text Node: Checks if text node is empty (only whitespace)
- Element Check: Recursively checks if all children are empty or
<br>tags
Show/Hide Logic
Show when:
- Editor is empty (passes
isEditorEmpty()check) - Editor is in WYSIWYG mode
- Editor is not read-only
Hide when:
- Editor has content
- Editor is in source code mode
- Editor is read-only
- Editor is being destructed
Style Adaptation
When showing placeholder:
- Position: Appends to
workplace(not inside editor) - Font Size: Matches first child element or editor
- Line Height: Matches first child element or editor
- Text Align: Matches current block or editor
- Padding: Matches editor padding (top, left, right)
- Margins: Uses max of editor and first child margins (top, left)
Event Triggers
Placeholder updates on:
change- Content changedfocus- Editor focusedkeyup- Key releasedmouseup- Mouse button releasedkeydown- Key pressedmousedown- Mouse button pressedafterSetMode- Editor mode changedchangePlace- Editor movedinput- Native input event (on editor element)readonly- Read-only state changed- Window
load- Page loaded
Debouncing
The toggle() method uses @debounce decorator:
- Delay:
defaultTimeout / 10(typically 10ms) - Leading edge:
true(executes immediately on first call) - Prevents excessive DOM updates during rapid events
RTL Support
For right-to-left languages:
- Sets
style.right = '0px' - Sets
style.direction = 'rtl' - Positions placeholder on right side
placeholder
Fired when placeholder text is determined/changed.
Parameters:
text(string): The placeholder text
Example:
editor.e.on('placeholder', (text) => {
console.log('Placeholder:', text);
});
readonly
Plugin listens to this event to hide placeholder in read-only mode.
Example:
editor.e.on('readonly', (isReadOnly) => {
console.log('Read-only changed:', isReadOnly);
});
Edge Cases
-
Read-Only Mode: Placeholder is hidden when editor is read-only
-
Source Mode: Placeholder is hidden in source code editing mode
-
Inseparable Tags: Editor with single image/video/iframe is not considered empty
-
Tables: Editor with table is not considered empty
-
BR Tags: Multiple
<br>tags are considered empty content -
Whitespace: Text nodes with only whitespace are considered empty
-
Markers: Selection markers are ignored when checking emptiness
-
First Child Styles: Placeholder inherits font-size and line-height from first child if available
-
RTL Direction: Placeholder automatically positioned on right for RTL languages
-
Mode Switching: Placeholder automatically hides when switching to source mode
Notes
- Plugin is class-based, extends
Pluginbase class - Placeholder element has
data-ref="placeholder"attribute - Placeholder uses
jodit-placeholderCSS class for styling - The placeholder is positioned absolutely and overlays the editor
- Initial
display: noneprevents flash of unstyled content - Plugin uses event namespacing (
.placeholder) for clean removal - The
@debouncedecorator optimizes performance during rapid events - Placeholder text is localized via
i18n()for multilingual support - The plugin checks for markers (selection indicators) when determining emptiness
- Placeholder is removed from DOM when hidden (not just hidden with CSS)
- Style calculation uses
getComputedStylefor accurate values - Margins use
Math.max()to handle both editor and child margins - Plugin listens to native
inputandkeydownevents on editor element - The
isEditorEmpty()function is exported for external use - Placeholder adapts to first element's typography for visual consistency
- Window load event ensures proper display after full page initialization
- The plugin properly cleans up all event listeners on destruction
- Placeholder element is created once and reused (not recreated on each show)
- The
toggle()method is the central logic for show/hide decisions - INSEPARABLE_TAGS constant defines media elements that indicate non-empty state
Typical Use Case
Users often need visual guidance when starting to edit in an empty editor. The placeholder plugin provides this by:
- Showing helpful text when editor is empty
- Automatically hiding when user starts typing
- Reappearing if user deletes all content
- Matching the editor's visual style for seamless integration
This improves user experience by:
- Providing clear instructions or context
- Indicating the editor is ready for input
- Maintaining consistent visual language with standard form elements
- Supporting multilingual interfaces through localization