- setAttributes( { buttonText: html } )
- }
- />
- ) }
- >
+ // borderColor, style, backgroundColor, textColor, gradient
+ const getNextButtonAttrs = ( prevAttrs = {} ) => ( {
+ borderColor: isButtonPositionInside ? attributes.borderColor : {},
+ style: {
+ ...attributes.style,
+ ...( isButtonPositionInside ? { borderRadius } : {} ),
+ },
+ backgroundColor: attributes.backgroundColor,
+ textColor: attributes.textColor,
+ gradient: attributes.gradient,
+ // TODO: Use icon when needed
+ text: prevAttrs.text || 'Search',
+ } );
+
+ const template = useMemo(
+ () => [ [ 'core/button', getNextButtonAttrs() ] ],
+ []
+ );
+ useEffect( () => {
+ const prevBlock = getBlocks( clientId )[ 0 ];
+ const nextBlock = cloneBlock(
+ prevBlock,
+ getNextButtonAttrs( prevBlock?.attributes ),
+ []
);
- };
+ replaceInnerBlocks( clientId, [ nextBlock ] );
+ }, [
+ isButtonPositionInside,
+ buttonUseIcon,
+ // Must serialize these two, they are new objects each time and
+ // keep triggering the effect
+ JSON.stringify( colorProps ),
+ JSON.stringify( borderProps ),
+ hasInnerBlocks,
+ clientId,
+ ] );
+
+ const innerBlocksProps = useInnerBlocksProps( blockProps, {
+ orientation: 'horizontal',
+ renderAppender: false,
+ template,
+ allowedBlocks: ALLOWED_BLOCKS,
+ } );
+ const button = ;
const controls = (
<>
@@ -439,10 +448,6 @@ export default function SearchEdit( {
return styles;
};
- const blockProps = useBlockProps( {
- className: getBlockClassNames(),
- } );
-
return (
{ controls }
@@ -457,7 +462,6 @@ export default function SearchEdit( {
onChange={ ( html ) => setAttributes( { label: html } ) }
/>
) }
-
{ renderTextField() }
- { renderButton() }
+ { button }
>
) }
- { hasOnlyButton && renderButton() }
+ { hasOnlyButton && button }
{ hasNoButton && renderTextField() }