From 07392e02cd16f60e96dfbc0b2433d22929d36a6f Mon Sep 17 00:00:00 2001 From: epiqueras Date: Fri, 12 Jul 2019 16:05:59 -0500 Subject: [PATCH] Post Title Block: Sync value with post slug. --- packages/block-library/src/post-title/block.json | 5 +++++ packages/block-library/src/post-title/edit.js | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/post-title/block.json b/packages/block-library/src/post-title/block.json index e5b162478055f4..feaa838e25e4f8 100644 --- a/packages/block-library/src/post-title/block.json +++ b/packages/block-library/src/post-title/block.json @@ -6,6 +6,11 @@ "type": "string", "source": "post", "attribute": "title" + }, + "slug": { + "type": "string", + "source": "post", + "attribute": "slug" } } } diff --git a/packages/block-library/src/post-title/edit.js b/packages/block-library/src/post-title/edit.js index 207c610162bd74..bc7d5da6236003 100644 --- a/packages/block-library/src/post-title/edit.js +++ b/packages/block-library/src/post-title/edit.js @@ -2,10 +2,7 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; - -/** - * WordPress dependencies - */ +import { cleanForSlug } from '@wordpress/editor'; import { RichText } from '@wordpress/block-editor'; export default function PostTitleEdit( { @@ -15,7 +12,7 @@ export default function PostTitleEdit( { return ( setAttributes( { title: value } ) } + onChange={ ( value ) => setAttributes( { title: value, slug: cleanForSlug( value ) } ) } tagName="h1" placeholder={ __( 'Title' ) } formattingControls={ [] }