Skip to content

Commit

Permalink
Rich Text: Add missing keep placeholder on focus prop. (#17439)
Browse files Browse the repository at this point in the history
* Rich Text: Add missing keep placeholder on focus prop.

* Use text cursor for the placeholder

* Turns out the cursor prop is not needed if the pointer-events prop is on the span instead of on the pseudo element
  • Loading branch information
epiqueras authored Sep 15, 2019
1 parent e62a670 commit 4f115c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class RichTextWrapper extends Component {
didAutomaticChange,
undo,
placeholder,
keepPlaceholderOnFocus,
// eslint-disable-next-line no-unused-vars
allowedFormats,
withoutInteractiveFormatting,
Expand Down Expand Up @@ -383,7 +384,10 @@ class RichTextWrapper extends Component {
selectionEnd={ selectionEnd }
onSelectionChange={ onSelectionChange }
tagName={ tagName }
className={ classnames( classes, className, { 'is-selected': originalIsSelected } ) }
className={ classnames( classes, className, {
'is-selected': originalIsSelected,
'keep-placeholder-on-focus': keepPlaceholderOnFocus,
} ) }
placeholder={ placeholder }
allowedFormats={ adjustedAllowedFormats }
withoutInteractiveFormatting={ withoutInteractiveFormatting }
Expand Down
7 changes: 5 additions & 2 deletions packages/block-editor/src/components/rich-text/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@
}
}

[data-rich-text-placeholder] {
pointer-events: none;
}

[data-rich-text-placeholder]::after {
content: attr(data-rich-text-placeholder);
pointer-events: none;
// Use opacity to work in various editor styles.
// We don't specify the color here, because blocks or editor styles might provide their own.
opacity: 0.62;
}

// Could be unset for individual rich text instances.
&.is-selected [data-rich-text-placeholder]::after {
&.is-selected:not(.keep-placeholder-on-focus) [data-rich-text-placeholder]::after {
display: none;
}
}
Expand Down

0 comments on commit 4f115c7

Please sign in to comment.