draft-js icon indicating copy to clipboard operation
draft-js copied to clipboard

Click on placeholder rather next to it

Open vincentdegheyndt opened this issue 6 years ago • 4 comments

Hello everyone,

I have been trying to modify the way the placeholder works in my project.

Currently, if I click next to the placeholder, it will place the caret where I want it to be and the text will start typing as expected. However if I click on the placeholder itself, it will select it as a normal text. Instead, I would like the caret to appear when i click on the placeholder.

Maybe I didn't search hard enough but i haven't found any information on that topic so far.

Thank you

vincentdegheyndt avatar Jun 03 '20 07:06 vincentdegheyndt

Hi @vincentdegheyndt, have you seen #403? See also the note about placeholder styling on https://draftjs.org/docs/api-reference-editor/.

thibaudcolas avatar Jun 03 '20 10:06 thibaudcolas

Thnaks @thibaudcolas,

Yes I have seen that issue and already used a custom css file to prevent that behaviour of the caret as they explain.

However I don't know of any css property that would make the placeholder text "unselectable". If there is then a custom css file should do the trick, I reckon.

EDIT : there's "user-select:none". It did make the placeholder unselectable as expected but I still have to click next to the placeholder for the caret to appear.

vincentdegheyndt avatar Jun 03 '20 15:06 vincentdegheyndt

Oh that’s strange – Draft.css is meant to come with the styles that do this, I think. Here are the relevant styles:

.DraftEditor-editorContainer {
    background-color: rgba(255, 255, 255, 0);
    border-left: .1px solid transparent;
    position: relative;
    z-index: 1;
}
.public-DraftEditorPlaceholder-root {
    color: #9197a3;
    position: absolute;
    z-index: 1;
}

At least in my editor this seems to be enough for the placeholder to not be clickable, since the "editor container" is in front of it.

thibaudcolas avatar Jun 03 '20 19:06 thibaudcolas

This worked !!!

Thank you very much for your help;

vincentdegheyndt avatar Jun 04 '20 06:06 vincentdegheyndt