diff --git a/packages/edit-site/src/components/header/document-actions/index.js b/packages/edit-site/src/components/header/document-actions/index.js index 02f8de9fbbfb9..e07f571c49d06 100644 --- a/packages/edit-site/src/components/header/document-actions/index.js +++ b/packages/edit-site/src/components/header/document-actions/index.js @@ -12,7 +12,7 @@ import { __experimentalGetBlockLabel as getBlockLabel, getBlockType, } from '@wordpress/blocks'; -import { useSelect } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { DOWN } from '@wordpress/keycodes'; function useSecondaryText() { @@ -46,9 +46,20 @@ export default function DocumentActions( { documentTitle } ) { const { page } = useSelect( ( select ) => { const { getPage } = select( 'core/edit-site' ); - return { page: getPage() }; + const { getEntityRecord } = select( 'core' ); + const _page = getPage(); + return { + page: getEntityRecord( 'postType', 'page', _page?.context?.postId ), + }; } ); + const { editEntityRecord } = useDispatch( 'core' ); + const editTitle = ( title ) => { + editEntityRecord( 'postType', 'page', page.id, { + title, + } ); + }; + return (
{ + const REGEXP_NEWLINES = /[\r\n]+/g; + const title = event.target.value.replace( + REGEXP_NEWLINES, + ' ' + ); + + editTitle( title ); + } } />
) }