Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

fix: add placeholder text for richtexteditor #1004

Merged
merged 5 commits into from
Jun 2, 2023
Merged
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
1 change: 1 addition & 0 deletions components/rich_text_editor/rich_text_editor.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const argsData = {
outputFormat: 'text',
autoFocus: false,
link: true,
placeholder: 'Type here...',
onBlur: action('blur'),
onInput: action('input'),
onFocus: action('focus'),
Expand Down
23 changes: 23 additions & 0 deletions components/rich_text_editor/rich_text_editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { Editor, EditorContent } from '@tiptap/vue-2';
import Document from '@tiptap/extension-document';
import Paragraph from '@tiptap/extension-paragraph';
import Placeholder from '@tiptap/extension-placeholder';
import Text from '@tiptap/extension-text';
import Link from './extensions/link';
import {
Expand Down Expand Up @@ -102,6 +103,14 @@ export default {
type: [Boolean, Object],
default: false,
},

/**
* Placeholder text
*/
placeholder: {
type: String,
default: '',
},
},

emits: [
Expand Down Expand Up @@ -147,6 +156,10 @@ export default {
if (this.link) {
extensions.push(this.getExtension(Link, this.link));
}
// Enable placeholder text
extensions.push(
Placeholder.configure({ placeholder: this.placeholder }),
);
return extensions;
},

Expand Down Expand Up @@ -283,3 +296,13 @@ export default {
},
};
</script>

<style>
.ProseMirror p.is-editor-empty:first-child::before {
content: attr(data-placeholder);
float: left;
color: var(--fc-placeholder);
pointer-events: none;
height: 0;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:output-format="outputFormat"
:auto-focus="autoFocus"
:link="link"
:placeholder="placeholder"
@blur="onBlur"
@input="onInput"
@focus="onFocus"
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@linusborg/vue-simple-portal": "^0.1.5",
"@tiptap/extension-document": "^2.0.2",
"@tiptap/extension-paragraph": "^2.0.2",
"@tiptap/extension-placeholder": "^2.0.3",
"@tiptap/extension-text": "^2.0.2",
"@tiptap/pm": "^2.0.2",
"@tiptap/vue-2": "^2.0.2",
Expand Down