diff --git a/packages/block-library/src/template-part/edit/index.js b/packages/block-library/src/template-part/edit/index.js index 64aaeaac2f9d1f..46c874ae3da4e4 100644 --- a/packages/block-library/src/template-part/edit/index.js +++ b/packages/block-library/src/template-part/edit/index.js @@ -3,6 +3,7 @@ */ import { useRef, useEffect } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; +import { ToolbarItem } from '@wordpress/components'; import { BlockControls, __experimentalBlock as Block, @@ -67,7 +68,8 @@ export default function TemplatePartEdit( { return ( - diff --git a/packages/block-library/src/template-part/edit/name-panel.js b/packages/block-library/src/template-part/edit/name-panel.js index e5a6eee52ebbca..ba7ba2966f9f37 100644 --- a/packages/block-library/src/template-part/edit/name-panel.js +++ b/packages/block-library/src/template-part/edit/name-panel.js @@ -1,12 +1,13 @@ /** * WordPress dependencies */ +import { forwardRef } from '@wordpress/element'; import { useEntityProp } from '@wordpress/core-data'; import { TextControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { cleanForSlug } from '@wordpress/url'; -export default function TemplatePartNamePanel( { postId, setAttributes } ) { +function TemplatePartNamePanel( { postId, setAttributes, ...props }, ref ) { const [ title, setTitle ] = useEntityProp( 'postType', 'wp_template_part', @@ -22,6 +23,8 @@ export default function TemplatePartNamePanel( { postId, setAttributes } ) { return (
{ @@ -30,8 +33,15 @@ export default function TemplatePartNamePanel( { postId, setAttributes } ) { setSlug( newSlug ); setAttributes( { slug: newSlug, postId } ); } } - onFocus={ ( event ) => event.target.select() } + onFocus={ ( event ) => { + if ( props.onFocus ) { + props.onFocus( event ); + } + event.target.select(); + } } />
); } + +export default forwardRef( TemplatePartNamePanel ); diff --git a/packages/components/src/text-control/index.js b/packages/components/src/text-control/index.js index a172eed483e50a..feae7a898387ac 100644 --- a/packages/components/src/text-control/index.js +++ b/packages/components/src/text-control/index.js @@ -2,22 +2,26 @@ * WordPress dependencies */ import { useInstanceId } from '@wordpress/compose'; +import { forwardRef } from '@wordpress/element'; /** * Internal dependencies */ import BaseControl from '../base-control'; -export default function TextControl( { - label, - hideLabelFromVision, - value, - help, - className, - onChange, - type = 'text', - ...props -} ) { +function TextControl( + { + label, + hideLabelFromVision, + value, + help, + className, + onChange, + type = 'text', + ...props + }, + ref +) { const instanceId = useInstanceId( TextControl ); const id = `inspector-text-control-${ instanceId }`; const onChangeValue = ( event ) => onChange( event.target.value ); @@ -37,8 +41,11 @@ export default function TextControl( { value={ value } onChange={ onChangeValue } aria-describedby={ !! help ? id + '__help' : undefined } + ref={ ref } { ...props } /> ); } + +export default forwardRef( TextControl );