@@ -72,6 +72,7 @@ export default function SearchEdit( {
7272 } = attributes ;
7373
7474 const borderRadius = style ?. border ?. radius ;
75+ const borderColor = style ?. border ?. color ;
7576 const borderProps = useBorderProps ( attributes ) ;
7677
7778 // Check for old deprecated numerical border radius. Done as a separate
@@ -83,6 +84,10 @@ export default function SearchEdit( {
8384
8485 const unitControlInstanceId = useInstanceId ( UnitControl ) ;
8586 const unitControlInputId = `wp-block-search__width-${ unitControlInstanceId } ` ;
87+ const isButtonPositionInside = 'button-inside' === buttonPosition ;
88+ const isButtonPositionOutside = 'button-outside' === buttonPosition ;
89+ const hasNoButton = 'no-button' === buttonPosition ;
90+ const hasOnlyButton = 'button-only' === buttonPosition ;
8691
8792 const units = useCustomUnits ( {
8893 availableUnits : [ '%' , 'px' ] ,
@@ -92,22 +97,19 @@ export default function SearchEdit( {
9297 const getBlockClassNames = ( ) => {
9398 return classnames (
9499 className ,
95- 'button-inside' === buttonPosition
100+ ! isButtonPositionInside ? borderProps . className : undefined ,
101+ isButtonPositionInside
96102 ? 'wp-block-search__button-inside'
97103 : undefined ,
98- 'button-outside' === buttonPosition
104+ isButtonPositionOutside
99105 ? 'wp-block-search__button-outside'
100106 : undefined ,
101- 'no-button' === buttonPosition
102- ? 'wp-block-search__no-button'
103- : undefined ,
104- 'button-only' === buttonPosition
105- ? 'wp-block-search__button-only'
106- : undefined ,
107- ! buttonUseIcon && 'no-button' !== buttonPosition
107+ hasNoButton ? 'wp-block-search__no-button' : undefined ,
108+ hasOnlyButton ? 'wp-block-search__button-only' : undefined ,
109+ ! buttonUseIcon && ! hasNoButton
108110 ? 'wp-block-search__text-button'
109111 : undefined ,
110- buttonUseIcon && 'no-button' !== buttonPosition
112+ buttonUseIcon && ! hasNoButton
111113 ? 'wp-block-search__icon-button'
112114 : undefined
113115 ) ;
@@ -163,21 +165,30 @@ export default function SearchEdit( {
163165 } ;
164166
165167 const getResizableSides = ( ) => {
166- if ( 'button-only' === buttonPosition ) {
168+ if ( hasOnlyButton ) {
167169 return { } ;
168170 }
169171
170172 return {
171- right : align === 'right' ? false : true ,
172- left : align === 'right' ? true : false ,
173+ right : align !== 'right' ,
174+ left : align === 'right' ,
173175 } ;
174176 } ;
175177
176178 const renderTextField = ( ) => {
179+ // If the input is inside the wrapper, the wrapper gets the border color styles/classes, not the input control.
180+ const textFieldClasses = classnames (
181+ 'wp-block-search__input' ,
182+ isButtonPositionInside ? undefined : borderProps . className
183+ ) ;
184+ const textFieldStyles = isButtonPositionInside
185+ ? { borderRadius }
186+ : borderProps . style ;
187+
177188 return (
178189 < input
179- className = "wp-block-search__input"
180- style = { borderProps . style }
190+ className = { textFieldClasses }
191+ style = { textFieldStyles }
181192 aria-label = { __ ( 'Optional placeholder text' ) }
182193 // We hide the placeholder field's placeholder when there is a value. This
183194 // stops screen readers from reading the placeholder field's placeholder
@@ -194,20 +205,29 @@ export default function SearchEdit( {
194205 } ;
195206
196207 const renderButton = ( ) => {
208+ // If the button is inside the wrapper, the wrapper gets the border color styles/classes, not the button.
209+ const buttonClasses = classnames (
210+ 'wp-block-search__button' ,
211+ isButtonPositionInside ? undefined : borderProps . className
212+ ) ;
213+ const buttonStyles = isButtonPositionInside
214+ ? { borderRadius }
215+ : borderProps . style ;
216+
197217 return (
198218 < >
199219 { buttonUseIcon && (
200220 < Button
201221 icon = { search }
202- className = "wp-block-search__button"
203- style = { borderProps . style }
222+ className = { buttonClasses }
223+ style = { buttonStyles }
204224 />
205225 ) }
206226
207227 { ! buttonUseIcon && (
208228 < RichText
209- className = "wp-block-search__button"
210- style = { borderProps . style }
229+ className = { buttonClasses }
230+ style = { buttonStyles }
211231 aria-label = { __ ( 'Button text' ) }
212232 placeholder = { __ ( 'Add button text…' ) }
213233 withoutInteractiveFormatting
@@ -240,7 +260,7 @@ export default function SearchEdit( {
240260 label = { __ ( 'Change button position' ) }
241261 controls = { buttonPositionControls }
242262 />
243- { 'no-button' !== buttonPosition && (
263+ { ! hasNoButton && (
244264 < ToolbarButton
245265 title = { __ ( 'Use button with icon' ) }
246266 icon = { buttonWithIcon }
@@ -329,13 +349,18 @@ export default function SearchEdit( {
329349 radius ? `calc(${ radius } + ${ DEFAULT_INNER_PADDING } )` : undefined ;
330350
331351 const getWrapperStyles = ( ) => {
352+ const styles = {
353+ borderColor,
354+ } ;
355+
332356 const isNonZeroBorderRadius = parseInt ( borderRadius , 10 ) !== 0 ;
333357
334- if ( 'button-inside' === buttonPosition && isNonZeroBorderRadius ) {
358+ if ( isButtonPositionInside && isNonZeroBorderRadius ) {
335359 // We have button inside wrapper and a border radius value to apply.
336360 // Add default padding so we don't get "fat" corners.
337361 //
338- // CSS calc() is used here to support non-pixel units.
362+ // CSS calc() is used here to support non-pixel units. The inline
363+ // style using calc() will only apply if both values have units.
339364
340365 if ( typeof borderRadius === 'object' ) {
341366 // Individual corner border radii present.
@@ -351,6 +376,7 @@ export default function SearchEdit( {
351376 borderTopRightRadius : padBorderRadius ( topRight ) ,
352377 borderBottomLeftRadius : padBorderRadius ( bottomLeft ) ,
353378 borderBottomRightRadius : padBorderRadius ( bottomRight ) ,
379+ ...styles ,
354380 } ;
355381 }
356382
@@ -361,12 +387,10 @@ export default function SearchEdit( {
361387 ? `${ borderRadius } px`
362388 : borderRadius ;
363389
364- return {
365- borderRadius : `calc(${ radius } + ${ DEFAULT_INNER_PADDING } )` ,
366- } ;
390+ styles . borderRadius = `calc(${ radius } + ${ DEFAULT_INNER_PADDING } )` ;
367391 }
368392
369- return undefined ;
393+ return styles ;
370394 } ;
371395
372396 const blockProps = useBlockProps ( {
@@ -392,7 +416,10 @@ export default function SearchEdit( {
392416 size = { {
393417 width : `${ width } ${ widthUnit } ` ,
394418 } }
395- className = "wp-block-search__inside-wrapper"
419+ className = { classnames (
420+ 'wp-block-search__inside-wrapper' ,
421+ isButtonPositionInside ? borderProps . className : undefined
422+ ) }
396423 style = { getWrapperStyles ( ) }
397424 minWidth = { MIN_WIDTH }
398425 enable = { getResizableSides ( ) }
@@ -411,16 +438,15 @@ export default function SearchEdit( {
411438 } }
412439 showHandle = { isSelected }
413440 >
414- { ( 'button-inside' === buttonPosition ||
415- 'button-outside' === buttonPosition ) && (
441+ { ( isButtonPositionInside || isButtonPositionOutside ) && (
416442 < >
417443 { renderTextField ( ) }
418444 { renderButton ( ) }
419445 </ >
420446 ) }
421447
422- { 'button-only' === buttonPosition && renderButton ( ) }
423- { 'no-button' === buttonPosition && renderTextField ( ) }
448+ { hasOnlyButton && renderButton ( ) }
449+ { hasNoButton && renderTextField ( ) }
424450 </ ResizableBox >
425451 </ div >
426452 ) ;
0 commit comments