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

Fix example code #6787

Merged
merged 1 commit into from
May 18, 2018
Merged

Fix example code #6787

merged 1 commit into from
May 18, 2018

Conversation

ajitbohra
Copy link
Member

@ajitbohra ajitbohra commented May 16, 2018

tagName missing

fixes #6763

Description

Docs Update

Types of changes

Docs update

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

tagName missing
@jorgefilipecosta
Copy link
Member

Hi @ajitbohra thank you for your contribution.
Checking the documentation of RichText component https://github.com/WordPress/gutenberg/tree/master/editor/components/rich-text it seems tagName is an optional prop and the default value should be a div. So it seems the documentation was not wrong and we have a bug in RichText component where it does not work correctly if tagName was no explicitly defined.

@NathanDJohnson
Copy link

@jorgefilipecosta the tagname is defined in the edit method as p but not the save method. If tagname defaults to div then there will still be a block validation error.

This is an error in the docs regardless of if there is also a bug in the RichText component.

But don't worry, @danielbachhuber closed the issue without resolving it.

@gziolo gziolo added the [Type] Developer Documentation Documentation for developers label May 17, 2018
@gziolo gziolo requested a review from youknowriad May 17, 2018 07:06
@gziolo gziolo added [Type] Bug An existing feature does not function as intended [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable labels May 17, 2018
@ajitbohra
Copy link
Member Author

@jorgefilipecosta

Have checked rich text docs you are right tagName is optional.
Looks like a bug as without tagName it's not rendering div.

If I am not wrong in the context of block edit/save we need to specify tagName so that it matches with the attributes schema. The example in docs needs "p" to properly get & save the data.

In rich text docs, we have tagName specified for both edit & save.

const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;

registerBlockType( /* ... */, {
	// ...

	attributes: {
		content: {
			type: 'array',
			source: 'children',
			selector: 'h2',
		},
	},

	edit( { className, attributes, setAttributes } ) {
		return (
			<RichText
				tagName="h2"
				className={ className }
				value={ attributes.content }
				onChange={ ( content ) => setAttributes( { content } ) }
			/>
		);
	},

	save( { attributes } ) {
		return <RichText.Content tagName="h2" value={ attributes.content } />;
	}
} );

@ajitbohra ajitbohra mentioned this pull request May 17, 2018
@youknowriad
Copy link
Contributor

Looks like a bug as without tagName it's not rendering div.

It's intended that without tagName, it shouldn't render a wrapper. I know it does for the edit part, but this is mandatory to enable TinyMCE. You can't enable TinyMCE on a fragment.

I agree the docs should be updated.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jorgefilipecosta jorgefilipecosta merged commit ab2cce2 into WordPress:master May 18, 2018
@jorgefilipecosta
Copy link
Member

Thank you for clarifying this @youknowriad.

@jorgefilipecosta the tagname is defined in the edit method as p but not the save method. If tagname defaults to div then there will still be a block validation error.

This is an error in the docs regardless of if there is also a bug in the RichText component.

You are right @NathanDJohnson thank you for referring this, I missed this check on the difference between edit and save. When comparing against RichText documentation I thought we might have a bug there.
I'm sorry for the confusion on my side @ajitbohra; I merged your PR thank you for the contribution 👍

@danielbachhuber danielbachhuber added this to the 2.9 milestone May 18, 2018
@ajitbohra
Copy link
Member Author

@jorgefilipecosta we were in the same boat :) thanks to @youknowriad for clarification

@ajitbohra ajitbohra deleted the patch-2 branch May 18, 2018 13:47
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 [Type] Bug An existing feature does not function as intended [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation Wrong
6 participants