@@ -163,14 +163,14 @@ function TemplateSelector({ onSelect, onClose, option, valueInForm }: TemplateSe
163
163
164
164
// if we are using only one template, we should settemplate to that template
165
165
useEffect ( ( ) => {
166
- if ( matchesOnlyOneTemplate ( valueInForm ) ) {
167
- const name = getTemplateName ( valueInForm ) ;
168
- setTemplate ( {
169
- name ,
170
- content : getContentFromOptions ( name , options ) ,
171
- } ) ;
172
- } else {
173
- if ( Boolean ( valueInForm ) ) {
166
+ if ( Boolean ( valueInForm ) ) {
167
+ if ( matchesOnlyOneTemplate ( valueInForm ) ) {
168
+ const name = getTemplateName ( valueInForm ) ;
169
+ setTemplate ( {
170
+ name ,
171
+ content : getContentFromOptions ( name , options ) ,
172
+ } ) ;
173
+ } else {
174
174
// if it's empty we default to select existing template
175
175
setTemplateOption ( 'Custom' ) ;
176
176
}
@@ -303,20 +303,16 @@ export function WrapWithTemplateSelection({
303
303
name,
304
304
children,
305
305
} : WrapWithTemplateSelectionProps ) {
306
- const { getValues } = useFormContext ( ) ;
307
- const value : string = getValues ( name ) ?? '' ;
308
- const emptyValue = value === '' || value === undefined ;
309
- const onlyOneTemplate = value ? matchesOnlyOneTemplate ( value ) : false ;
310
306
const styles = useStyles2 ( getStyles ) ;
311
-
307
+ const { getValues } = useFormContext ( ) ;
308
+ const value = getValues ( name ) ?? '' ;
312
309
// if the placeholder does not contain a template, we don't need to show the template picker
313
- if ( ! option . placeholder . includes ( '{{ template ' ) ) {
310
+ if ( ! option . placeholder . includes ( '{{ template ' ) || typeof value !== 'string' ) {
314
311
return < > { children } </ > ;
315
312
}
316
313
// Otherwise, we can use templates on this field
317
-
318
314
// if the value is empty, we only show the template picker
319
- if ( emptyValue ) {
315
+ if ( ! value ) {
320
316
return (
321
317
< div className = { styles . inputContainer } >
322
318
< Stack direction = "row" gap = { 1 } alignItems = "center" >
@@ -327,6 +323,7 @@ export function WrapWithTemplateSelection({
327
323
</ div >
328
324
) ;
329
325
}
326
+ const onlyOneTemplate = value ? matchesOnlyOneTemplate ( value ) : false ;
330
327
if ( onlyOneTemplate ) {
331
328
return (
332
329
< div className = { styles . inputContainer } >
0 commit comments