-
-
Save reza-ebrahimi/9d11904e3df64dcd1fb13c1db10e1d56 to your computer and use it in GitHub Desktop.
Prosemirror placeholder plugin approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.ProseMirror[data-placeholder]::before { | |
color: global.$placeholder-colour; | |
position: absolute; | |
content: attr(data-placeholder); | |
pointer-events: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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