diff --git a/packages/block-library/src/search/block.json b/packages/block-library/src/search/block.json index b96f14f53c778c..54bb6b43635bdd 100644 --- a/packages/block-library/src/search/block.json +++ b/packages/block-library/src/search/block.json @@ -42,6 +42,7 @@ "supports": { "align": [ "left", "center", "right" ], "__experimentalBorder": { + "color": true, "radius": true, "__experimentalSkipSerialization": true }, diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index e279fcb0ad002b..7bb783ee0fd97f 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -72,6 +72,7 @@ export default function SearchEdit( { } = attributes; const borderRadius = style?.border?.radius; + const borderColor = style?.border?.color; const borderProps = useBorderProps( attributes ); // Check for old deprecated numerical border radius. Done as a separate @@ -83,6 +84,10 @@ export default function SearchEdit( { const unitControlInstanceId = useInstanceId( UnitControl ); const unitControlInputId = `wp-block-search__width-${ unitControlInstanceId }`; + const isButtonPositionInside = 'button-inside' === buttonPosition; + const isButtonPositionOutside = 'button-outside' === buttonPosition; + const hasNoButton = 'no-button' === buttonPosition; + const hasOnlyButton = 'button-only' === buttonPosition; const units = useCustomUnits( { availableUnits: [ '%', 'px' ], @@ -92,22 +97,19 @@ export default function SearchEdit( { const getBlockClassNames = () => { return classnames( className, - 'button-inside' === buttonPosition + ! isButtonPositionInside ? borderProps.className : undefined, + isButtonPositionInside ? 'wp-block-search__button-inside' : undefined, - 'button-outside' === buttonPosition + isButtonPositionOutside ? 'wp-block-search__button-outside' : undefined, - 'no-button' === buttonPosition - ? 'wp-block-search__no-button' - : undefined, - 'button-only' === buttonPosition - ? 'wp-block-search__button-only' - : undefined, - ! buttonUseIcon && 'no-button' !== buttonPosition + hasNoButton ? 'wp-block-search__no-button' : undefined, + hasOnlyButton ? 'wp-block-search__button-only' : undefined, + ! buttonUseIcon && ! hasNoButton ? 'wp-block-search__text-button' : undefined, - buttonUseIcon && 'no-button' !== buttonPosition + buttonUseIcon && ! hasNoButton ? 'wp-block-search__icon-button' : undefined ); @@ -163,21 +165,30 @@ export default function SearchEdit( { }; const getResizableSides = () => { - if ( 'button-only' === buttonPosition ) { + if ( hasOnlyButton ) { return {}; } return { - right: align === 'right' ? false : true, - left: align === 'right' ? true : false, + right: align !== 'right', + left: align === 'right', }; }; const renderTextField = () => { + // If the input is inside the wrapper, the wrapper gets the border color styles/classes, not the input control. + const textFieldClasses = classnames( + 'wp-block-search__input', + isButtonPositionInside ? undefined : borderProps.className + ); + const textFieldStyles = isButtonPositionInside + ? { borderRadius } + : borderProps.style; + return ( { + // If the button is inside the wrapper, the wrapper gets the border color styles/classes, not the button. + const buttonClasses = classnames( + 'wp-block-search__button', + isButtonPositionInside ? undefined : borderProps.className + ); + const buttonStyles = isButtonPositionInside + ? { borderRadius } + : borderProps.style; + return ( <> { buttonUseIcon && (