Skip to content

Instantly share code, notes, and snippets.

@JSoon
Forked from amk221/placeholder.css
Created February 14, 2025 06:34
Show Gist options
  • Select an option

  • Save JSoon/bcbffb68c8666cb4e23e226600664795 to your computer and use it in GitHub Desktop.

Select an option

Save JSoon/bcbffb68c8666cb4e23e226600664795 to your computer and use it in GitHub Desktop.
Prosemirror placeholder plugin approach
.ProseMirror[data-placeholder]::before {
color: global.$placeholder-colour;
position: absolute;
content: attr(data-placeholder);
pointer-events: none;
}
import { Plugin } from 'prosemirror-state';
export default function placeholder(text) {
const update = (view) => {
if (view.state.doc.textContent) {
view.dom.removeAttribute('data-placeholder');
} else {
view.dom.setAttribute('data-placeholder', text);
}
};
return new Plugin({
view(view) {
update(view);
return { update };
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment