Switch branches/tags
@wordpress/wordcount@2.0.2 @wordpress/wordcount@2.0.1 @wordpress/wordcount@2.0.0 @wordpress/wordcount@1.1.3 @wordpress/wordcount@1.1.2 @wordpress/wordcount@1.1.1 @wordpress/wordcount@1.1.0 @wordpress/viewport@2.0.3 @wordpress/viewport@2.0.2 @wordpress/viewport@2.0.1 @wordpress/viewport@2.0.0 @wordpress/viewport@1.0.4 @wordpress/viewport@1.0.3 @wordpress/viewport@1.0.2 @wordpress/viewport@1.0.1 @wordpress/viewport@1.0.0 @wordpress/url@2.1.0 @wordpress/url@2.0.2 @wordpress/url@2.0.1 @wordpress/url@2.0.0 @wordpress/url@1.2.3 @wordpress/url@1.2.2 @wordpress/url@1.2.1 @wordpress/url@1.2.0 @wordpress/token-list@1.0.2 @wordpress/token-list@1.0.1 @wordpress/token-list@1.0.0 @wordpress/shortcode@2.0.2 @wordpress/shortcode@2.0.1 @wordpress/shortcode@2.0.0 @wordpress/shortcode@1.0.3 @wordpress/shortcode@1.0.2 @wordpress/shortcode@1.0.1 @wordpress/shortcode@1.0.0 @wordpress/shortcode@1.0.0-alpha.3 @wordpress/shortcode@1.0.0-alpha.2 @wordpress/scripts@2.4.0 @wordpress/scripts@2.3.1 @wordpress/scripts@2.3.0 @wordpress/scripts@2.2.1 @wordpress/scripts@2.2.0 @wordpress/scripts@2.1.0 @wordpress/scripts@2.0.3 @wordpress/scripts@2.0.2 @wordpress/scripts@2.0.1 @wordpress/scripts@2.0.0 @wordpress/rich-text@1.0.0-beta.2 @wordpress/rich-text@1.0.0-beta.1 @wordpress/redux-routine@3.0.1 @wordpress/redux-routine@3.0.0 @wordpress/redux-routine@2.0.0 @wordpress/redux-routine@1.0.0 @wordpress/postcss-themes@1.0.4 @wordpress/postcss-themes@1.0.3 @wordpress/postcss-themes@1.0.2 @wordpress/postcss-themes@1.0.1 @wordpress/postcss-themes@1.0.0 @wordpress/postcss-themes@1.0.0-alpha.3 @wordpress/postcss-themes@1.0.0-alpha.2 @wordpress/postcss-themes@1.0.0-alpha.1 @wordpress/postcss-themes@1.0.0-alpha.0 @wordpress/plugins@2.0.3 @wordpress/plugins@2.0.2 @wordpress/plugins@2.0.1 @wordpress/plugins@2.0.0 @wordpress/plugins@1.0.4 @wordpress/plugins@1.0.3 @wordpress/plugins@1.0.2 @wordpress/plugins@1.0.1 @wordpress/plugins@1.0.0 @wordpress/plugins@1.0.0-alpha.3 @wordpress/plugins@1.0.0-alpha.2 @wordpress/nux@2.0.3 @wordpress/nux@2.0.2 @wordpress/nux@2.0.1 @wordpress/nux@2.0.0 @wordpress/nux@1.1.1 @wordpress/nux@1.1.0 @wordpress/nux@1.0.2 @wordpress/nux@1.0.1 @wordpress/nux@1.0.0 @wordpress/npm-package-json-lint-config@1.1.5 @wordpress/npm-package-json-lint-config@1.1.4 @wordpress/npm-package-json-lint-config@1.1.3 @wordpress/npm-package-json-lint-config@1.1.2 @wordpress/npm-package-json-lint-config@1.1.1 @wordpress/npm-package-json-lint-config@1.1.0 @wordpress/list-reusable-blocks@1.1.1 @wordpress/list-reusable-blocks@1.1.0 @wordpress/list-reusable-blocks@1.0.1 @wordpress/library-export-default-webpack-plugin@1.0.4 @wordpress/library-export-default-webpack-plugin@1.0.3 @wordpress/library-export-default-webpack-plugin@1.0.2 @wordpress/library-export-default-webpack-plugin@1.0.1 @wordpress/library-export-default-webpack-plugin@1.0.0 @wordpress/library-export-default-webpack-plugin@1.0.0-alpha.3 @wordpress/library-export-default-webpack-plugin@1.0.0-alpha.2 @wordpress/library-export-default-webpack-plugin@1.0.0-alpha.1 @wordpress/library-export-default-webpack-plugin@1.0.0-alpha.0 @wordpress/keycodes@2.0.2
Nothing to show
Find file History
daniloercoli [RNMobile] Split Para/Heading blocks on enter.KEY - step 1 (#10553)
* The RichText component calls `onSplit` - if defined - on the parent component, when enter.KEY is detected.
Para block for mobile now has onSplit defined, that in this first implementation tries to add a test  block after.

* Do not include HTML tags in demo content

* Add onSplit method to Heading block for mobile, and wire to insertBlockAfter if defined in props.

* Add TODO, and remove empty lines
Latest commit a9a27bb Oct 16, 2018

README.md

RichText

Render a rich contenteditable input, providing users the option to add emphasis to content or links to content. It behaves similarly to a controlled component, except that onChange is triggered less frequently than would be expected from a traditional input field, usually when the user exits the field.

Properties

format: String

Optional. Format of the RichText provided value prop. It can be children or string.

Default: children.

value: Array|String

Required. Depending on the format prop, this value could be an array of React DOM to make editable or an HTML string. The rendered HTML should be valid, and valid with respect to the tagName and inline property.

onChange( value: Array|String ): Function

Required. Called when the value changes.

tagName: String

Default: div. The tag name of the editable element.

placeholder: String

Optional. Placeholder text to show when the field is empty, similar to the input and textarea attribute of the same name.

multiline: String

Optional. By default, a line break will be inserted on Enter. If the editable field can contain multiple paragraphs, this property can be set to p to create new paragraphs on Enter.

onSplit( before: Array|String, after: Array|String, ...blocks: Object ): Function

Optional. Called when the content can be split with before and after. There might be blocks present, which should be inserted in between.

onReplace( blocks: Array ): Function

Optional. Called when the RichText instance is empty and it can be replaced with the given blocks.

onMerge( forward: Boolean ): Function

Optional. Called when blocks can be merged. forward is true when merging with the next block, false when merging with the previous block.

onRemove( forward: Boolean ): Function

Optional. Called when the block can be removed. forward is true when the selection is expected to move to the next block, false to the previous block.

formattingControls: Array

Optional. By default, all formatting controls are present. This setting can be used to fine-tune formatting controls. Possible items: [ 'bold', 'italic', 'strikethrough', 'link' ].

isSelected: Boolean

Optional. Whether to show the input is selected or not in order to show the formatting controls. By default it renders the controls when the block is selected.

keepPlaceholderOnFocus: Boolean

Optional. By default, the placeholder will hide as soon as the editable field receives focus. With this setting it can be be kept while the field is focussed and empty.

autocompleters: Array<Completer>

Optional. A list of autocompleters to use instead of the default.

RichText.Content

RichText.Content should be used in the save function of your block to correctly save rich text content.

Example

{% codetabs %} {% ES5 %}

wp.blocks.registerBlockType( /* ... */, {
	// ...

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

	edit: function( props ) {
		return wp.element.createElement( wp.editor.RichText, {
			tagName: 'h2',
			className: props.className,
			value: props.attributes.content,
			onChange: function( content ) {
				props.setAttributes( { content: content } );
			}
		} );
	},

	save: function() {
		return wp.element.createElement( wp.editor.RichText.Content, {
			tagName: 'h2', value: props.attributes.content
		} );
	}
} );

{% ESNext %}

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 } />;
	}
} );

{% end %}