Skip to content

Commit

Permalink
Site Editor: Allow clearing template name field while typing (#42149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Jul 5, 2022
1 parent 65a89c9 commit 64a42a2
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import { __ } from '@wordpress/i18n';
import { TextControl } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import { useState } from '@wordpress/element';

export default function EditTemplateTitle( { template } ) {
const [ forceEmpty, setForceEmpty ] = useState( false );
const [ title, setTitle ] = useEntityProp(
'postType',
template.type,
Expand All @@ -16,13 +18,19 @@ export default function EditTemplateTitle( { template } ) {
return (
<TextControl
label={ __( 'Title' ) }
value={ title }
value={ forceEmpty ? '' : title }
help={ __(
'Give the template a title that indicates its purpose, e.g. "Full Width".'
) }
onChange={ ( newTitle ) => {
setTitle( newTitle || template.slug );
if ( ! newTitle && ! forceEmpty ) {
setForceEmpty( true );
return;
}
setForceEmpty( false );
setTitle( newTitle );
} }
onBlur={ () => setForceEmpty( false ) }
/>
);
}

0 comments on commit 64a42a2

Please sign in to comment.