Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolbar showing for TextControl when RichText is not selected #7463

Closed
grappler opened this issue Jun 22, 2018 · 12 comments
Closed

Toolbar showing for TextControl when RichText is not selected #7463

grappler opened this issue Jun 22, 2018 · 12 comments
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable Needs Dev Ready for, and needs developer efforts [Type] Bug An existing feature does not function as intended
Milestone

Comments

@grappler
Copy link
Member

grappler commented Jun 22, 2018

Follow the test method descriped in Issue #16651 as the test case involved a core block.


I have created a block with both TextControl and RichText.

When I select the RichText I get the toolbar but the toolbar does not disappear when the TextControl is selected. I have tested this with Gutenberg 3.1

Here is a screenshot of the block with the TextControl and RichText.
image

I have created a example plugin where this can be tested: grappler-block.zip

The code it the edit is

<div className={ className }>
	<TextControl
		label={ __( 'TextControl' ) }
		value={ attributes.textControl || '' }
		type="text"
		onChange={ ( newValue ) => {
			setAttributes( { textControl: newValue } );
		} }
	/>

	<RichText
		multiline="li"
		tagName="ul"
		formattingControls={ [ 'bold', 'link' ] }
		value={ attributes.richText }
		placeholder={ __( 'RichText' ) }
		onChange={ ( content ) => setAttributes( { richText: content } ) }
	/>
</div>

This was previously working with a custom onFocus.

Related PRs #7029 & #6871

@gziolo gziolo added [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Bug An existing feature does not function as intended labels Jun 22, 2018
@gziolo
Copy link
Member

gziolo commented Jun 22, 2018

Thanks for reporting. So as you noticed, we tried to automate also unfocusing RichText in #6871 to make sure that those controls get removed when other element/component gets focus. The idea is to have your code as simple as possible, but let Gutenberg handle everything else.

There is also a different but related issue to this one:

When transforming blocks with RichText from one type to another (e.g. Quote to Paragraph), immediately after the transformation, only alignment buttons are visible in the toolbar but not rich-text buttons, until I place the caret.

We just need to better understand what would be the best way to tackle all those flows plugin developers would like to have.

@gziolo
Copy link
Member

gziolo commented Nov 12, 2018

I can confirm, it's still an issue.

@jorgefilipecosta
Copy link
Member

With Gutenberg 5.8 and the last version of WordPress, the problem is still happening.

@gziolo gziolo removed their assignment Jun 7, 2019
@gziolo gziolo added the Needs Dev Ready for, and needs developer efforts label Jun 7, 2019
@talldan
Copy link
Contributor

talldan commented Apr 22, 2020

Just discovered this, closing my duplicate - #16651

This is very easily tested in the Search block, which has a RichText and a TextArea.

@adamziel
Copy link
Contributor

adamziel commented Apr 23, 2020

The root cause is that unless isSelected prop is provided, the <RichText /> component uses useBlockEditContext().isSelected to determine whether or not it should display the format toolbar:

const {
clientId,
onCaretVerticalPositionChange,
isSelected: blockIsSelected,
} = useBlockEditContext();

{ nestedIsSelected && hasFormats && (
<FormatToolbarContainer
inline={ inlineToolbar }
anchorRef={ ref.current }
/>
) }

When you select the rich text first, and then switch to the input, the block remains selected so the buttons don't disappear. I looked up why is it not an issue in e.g. the image block where the caption is also RichText, and there's some custom code in place to override the value of isSelected:

<RichText
tagName="figcaption"
placeholder={ __( 'Write caption…' ) }
value={ caption }
unstableOnFocus={ this.onFocusCaption }
onChange={ ( value ) =>
setAttributes( { caption: value } )
}
isSelected={ this.state.captionFocused }
inlineToolbar
/>

One idea would be to check focus instead (or in addition to isSelected).

@adamziel
Copy link
Contributor

adamziel commented Apr 23, 2020

A quick experiment confirms it would work:

2020-04-23 12-06-52 2020-04-23 12_08_57

An experimental branch available here:

#21818

It's not clean mergable code and requires some more care (like analyzing why onFocus is exposed as unstableOnFocus - this is a potential show stopper). I only played with it during the triage session so please feel free to take over and roll out a proper PR.

@paaljoachim
Copy link
Contributor

Can we get an update from someone on this issue?
Thank you!

@talldan

@talldan
Copy link
Contributor

talldan commented Feb 22, 2021

@paaljoachim Have you tested to see if it's still an issue?

@grappler
Copy link
Member Author

@talldan I have tested it again with WordPress 5.6 and Gutenberg 10.0 snd can confirm this is still an issue.

@talldan
Copy link
Contributor

talldan commented Feb 22, 2021

Thanks @grappler.

@glendaviesnz
Copy link
Contributor

@grappler, this seems to be resolved in 5.8 with Gutenberg plugin 11.3.0:
menu

@grappler
Copy link
Member Author

Tested with WordPress 5.8 and it works as expected. Closing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable Needs Dev Ready for, and needs developer efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

8 participants