add new dataAttribute option for placeholders#7468
Conversation
🦋 Changeset detectedLatest commit: f846d96 The changes in this PR will be included in the next version bump. This PR includes changesets to release 72 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Adds a configurable dataAttribute option to the Placeholder extension so consumers can choose which data-* attribute name is used for placeholder labels (useful for custom CSS selectors).
Changes:
- Added
dataAttributetoPlaceholderOptions(default:placeholder) and wired it into the decoration attributes. - Introduced
preparePlaceholderAttribute()to normalize/sanitize the configured attribute name. - Added unit tests and a changeset entry for the new option.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| packages/extensions/src/placeholder/placeholder.ts | Adds the new option + attribute-name preparation and uses it when creating placeholder decorations. |
| packages/extensions/src/placeholder/placeholder.spec.ts | Adds unit tests validating default/custom attribute behavior and sanitization. |
| .changeset/placeholder-data-attribute.md | Declares a patch release for @tiptap/extensions documenting the new option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@tiptap/core
@tiptap/extension-blockquote
@tiptap/extension-audio
@tiptap/extension-bold
@tiptap/extension-bubble-menu
@tiptap/extension-bullet-list
@tiptap/extension-code
@tiptap/extension-code-block
@tiptap/extension-code-block-lowlight
@tiptap/extension-collaboration
@tiptap/extension-collaboration-caret
@tiptap/extension-details
@tiptap/extension-color
@tiptap/extension-document
@tiptap/extension-drag-handle
@tiptap/extension-drag-handle-react
@tiptap/extension-drag-handle-vue-2
@tiptap/extension-drag-handle-vue-3
@tiptap/extension-file-handler
@tiptap/extension-emoji
@tiptap/extension-floating-menu
@tiptap/extension-font-family
@tiptap/extension-hard-break
@tiptap/extension-heading
@tiptap/extension-highlight
@tiptap/extension-horizontal-rule
@tiptap/extension-image
@tiptap/extension-invisible-characters
@tiptap/extension-italic
@tiptap/extension-link
@tiptap/extension-list
@tiptap/extension-mathematics
@tiptap/extension-mention
@tiptap/extension-node-range
@tiptap/extension-ordered-list
@tiptap/extension-paragraph
@tiptap/extension-strike
@tiptap/extension-subscript
@tiptap/extension-superscript
@tiptap/extension-table
@tiptap/extension-table-of-contents
@tiptap/extension-text
@tiptap/extension-text-align
@tiptap/extension-text-style
@tiptap/extension-twitch
@tiptap/extension-typography
@tiptap/extension-underline
@tiptap/extension-unique-id
@tiptap/extensions
@tiptap/extension-youtube
@tiptap/html
@tiptap/markdown
@tiptap/react
@tiptap/starter-kit
@tiptap/pm
@tiptap/static-renderer
@tiptap/suggestion
@tiptap/vue-2
@tiptap/vue-3
@tiptap/extension-character-count
@tiptap/extension-focus
@tiptap/extension-dropcursor
@tiptap/extension-gapcursor
@tiptap/extension-history
@tiptap/extension-list-item
@tiptap/extension-list-keymap
@tiptap/extension-placeholder
@tiptap/extension-table-cell
@tiptap/extension-table-header
@tiptap/extension-table-row
@tiptap/extension-task-item
@tiptap/extension-task-list
commit: |
What exactly would a generic approach look like here? Do you have anything in mind? |
Changes Overview
Added a new
dataAttributeoption to the Placeholder extension that allows developers to customize which data attribute name is used for the placeholder label. This provides more flexibility when styling placeholders with custom CSS selectors.Implementation Approach
dataAttributeoption toPlaceholderOptionsinterface with a default value of'placeholder'preparePlaceholderAttribute()utility function to sanitize and normalize attribute names:dataAttributewhen creating DOM decorationsdata-to ensure valid HTMLTesting Done
Added comprehensive unit tests covering:
data-placeholderwhen no option is provided)Tests verify that the correct data attribute is applied to empty nodes and that the placeholder text is properly set.
Verification Steps
dataAttributeoption:Placeholder.configure({ placeholder: 'Add content...', dataAttribute: 'my-custom-label' })data-my-custom-labelattribute[data-my-custom-label]::before { content: attr(data-my-custom-label); }Additional Notes
The
preparePlaceholderAttribute()function ensures that user-provided attribute names are automatically sanitized to produce valid HTML data attributes, preventing runtime errors or unexpected behavior.Checklist
Related Issues
No related issues.