WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

RichText: When clicking on a RichText with keepPlaceholderOnFocus the caret doesn't appear #31289

Open atimmer opened 3 years ago

atimmer commented 3 years ago

Description

When clicking with the mouse on a RichText that has keepPlaceholderOnFocus set to true the caret doesn't appear.

Step-by-step reproduction instructions

JavaScript for a reduced block ```js import { RichText, useBlockProps } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; export const name = 'atimmer/placeholder-test', settings = { apiVersion: 2, title: __( 'Placeholder test', 'shiro' ), attributes: { content: { type: 'string', source: 'html', selector: '.placeholder-test__content', }, }, edit: function EditPlaceholderTest( { attributes, setAttributes } ) { const blockProps = useBlockProps( { className: 'placeholder-test' } ); const { content } = attributes; return ( setAttributes( { content } ) } /> ); }, save: function SavePlaceholderTest( { attributes } ) { const blockProps = useBlockProps.save( { className: 'placeholder-test' } ); const { content } = attributes; return ( ); }, }; ```
Browser console version ```js wp.blocks.registerBlockType( 'atimmer/placeholder-test', { apiVersion: 2, title: 'Placeholder test', attributes: { content: { type: 'string', source: 'html', selector: '.placeholder-test__content', }, }, edit: function EditPlaceholderTest( { attributes, setAttributes } ) { const blockProps = wp.blockEditor.useBlockProps( { className: 'placeholder-test' } ); const { content } = attributes; return wp.element.createElement( wp.blockEditor.RichText, { ...blockProps, keepPlaceholderOnFocus: true, placeholder: 'Write in RichText', value: content, onChange: content => setAttributes( { content } ), } ); }, save: function SavePlaceholderTest( { attributes } ) { const blockProps = wp.blockEditor.useBlockProps.save( { className: 'placeholder-test' } ); const { content } = attributes; return wp.element.createElement( wp.blockEditor.RichText, { ...blockProps, value: content, } ); }, } ); ```
  1. Register the above block with your preferred Webpack solution.
  2. Insert the above block in your post/page
  3. Click on the RichText ("Write in RichText" placeholder)
  4. The caret is now not shown anywhere.

Expected behaviour

I expected the caret to always be shown.

Actual behaviour

The caret is not consistently shown.

Screenshots or screen recording (optional)

In the screen recording you can see that it rarely doesn't happen. And that when I click a second time it does show the caret. I have found that with more complex setups (more styling), the second click doesn't necessarily show the caret. So this is a bug present in Gutenberg core, but exacerbated by more CSS.

Placeholder bug

Code snippet (optional)

WordPress information

Device information

johnstonphilip commented 3 years ago

Fwiw, that prop seems to have been removed at some point. It doesn't show up in the code anymore: https://github.com/WordPress/gutenberg/search?q=keepPlaceholderOnFocus

It appears it was accidentally removed at some point, and then re-added: https://github.com/WordPress/gutenberg/pull/17439

But I don't see it at all in the code today: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/rich-text/index.js

I am also getting this error on some older block code in the console: react-dom.860550b4.js:61 Warning: React does not recognize thekeepPlaceholderOnFocusprop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercasekeepplaceholderonfocusinstead. If you accidentally passed it from a parent component, remove it from the DOM element.

ellatrix commented 3 years ago

The prop has been remove because we now always keep the placeholder on focus.

ellatrix commented 1 year ago

Is this still an issue? I can't seem to reproduce in Firefox.