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 && (
) }
{ ! buttonUseIcon && (
- { 'no-button' !== buttonPosition && (
+ { ! hasNoButton && (
{
+ const styles = {
+ borderColor,
+ };
+
const isNonZeroBorderRadius = parseInt( borderRadius, 10 ) !== 0;
- if ( 'button-inside' === buttonPosition && isNonZeroBorderRadius ) {
+ if ( isButtonPositionInside && isNonZeroBorderRadius ) {
// We have button inside wrapper and a border radius value to apply.
// Add default padding so we don't get "fat" corners.
//
- // CSS calc() is used here to support non-pixel units.
+ // CSS calc() is used here to support non-pixel units. The inline
+ // style using calc() will only apply if both values have units.
if ( typeof borderRadius === 'object' ) {
// Individual corner border radii present.
@@ -351,6 +376,7 @@ export default function SearchEdit( {
borderTopRightRadius: padBorderRadius( topRight ),
borderBottomLeftRadius: padBorderRadius( bottomLeft ),
borderBottomRightRadius: padBorderRadius( bottomRight ),
+ ...styles,
};
}
@@ -361,12 +387,10 @@ export default function SearchEdit( {
? `${ borderRadius }px`
: borderRadius;
- return {
- borderRadius: `calc(${ radius } + ${ DEFAULT_INNER_PADDING })`,
- };
+ styles.borderRadius = `calc(${ radius } + ${ DEFAULT_INNER_PADDING })`;
}
- return undefined;
+ return styles;
};
const blockProps = useBlockProps( {
@@ -392,7 +416,10 @@ export default function SearchEdit( {
size={ {
width: `${ width }${ widthUnit }`,
} }
- className="wp-block-search__inside-wrapper"
+ className={ classnames(
+ 'wp-block-search__inside-wrapper',
+ isButtonPositionInside ? borderProps.className : undefined
+ ) }
style={ getWrapperStyles() }
minWidth={ MIN_WIDTH }
enable={ getResizableSides() }
@@ -411,16 +438,15 @@ export default function SearchEdit( {
} }
showHandle={ isSelected }
>
- { ( 'button-inside' === buttonPosition ||
- 'button-outside' === buttonPosition ) && (
+ { ( isButtonPositionInside || isButtonPositionOutside ) && (
<>
{ renderTextField() }
{ renderButton() }
>
) }
- { 'button-only' === buttonPosition && renderButton() }
- { 'no-button' === buttonPosition && renderTextField() }
+ { hasOnlyButton && renderButton() }
+ { hasNoButton && renderTextField() }
);
diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php
index 2b6d74d52a1c0e..9014bf7f990a79 100644
--- a/packages/block-library/src/search/index.php
+++ b/packages/block-library/src/search/index.php
@@ -27,16 +27,20 @@ function render_block_core_search( $attributes ) {
)
);
- $input_id = 'wp-block-search__input-' . ++$instance_id;
- $classnames = classnames_for_block_core_search( $attributes );
- $show_label = ( ! empty( $attributes['showLabel'] ) ) ? true : false;
- $use_icon_button = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
- $show_input = ( ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'] ) ? false : true;
- $show_button = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
- $label_markup = '';
- $input_markup = '';
- $button_markup = '';
- $inline_styles = styles_for_block_core_search( $attributes );
+ $input_id = 'wp-block-search__input-' . ++$instance_id;
+ $classnames = classnames_for_block_core_search( $attributes );
+ $show_label = ( ! empty( $attributes['showLabel'] ) ) ? true : false;
+ $use_icon_button = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
+ $show_input = ( ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'] ) ? false : true;
+ $show_button = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
+ $label_markup = '';
+ $input_markup = '';
+ $button_markup = '';
+ $inline_styles = styles_for_block_core_search( $attributes );
+ $is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
+ 'button-inside' === $attributes['buttonPosition'];
+ // Border color classes need to be applied to the elements that have a border color.
+ $border_color_classes = get_border_color_classes_for_block_core_search( $attributes );
if ( $show_label ) {
if ( ! empty( $attributes['label'] ) ) {
@@ -55,9 +59,11 @@ function render_block_core_search( $attributes ) {
}
if ( $show_input ) {
- $input_markup = sprintf(
- '',
+ $input_classes = ! $is_button_inside ? $border_color_classes : '';
+ $input_markup = sprintf(
+ '',
$input_id,
+ $input_classes,
esc_attr( get_search_query() ),
esc_attr( $attributes['placeholder'] ),
$inline_styles['shared']
@@ -66,14 +72,14 @@ function render_block_core_search( $attributes ) {
if ( $show_button ) {
$button_internal_markup = '';
- $button_classes = '';
+ $button_classes = ! $is_button_inside ? $border_color_classes : '';
if ( ! $use_icon_button ) {
if ( ! empty( $attributes['buttonText'] ) ) {
$button_internal_markup = $attributes['buttonText'];
}
} else {
- $button_classes .= 'has-icon';
+ $button_classes .= ' has-icon';
$button_internal_markup =
'