Skip to content

Commit

Permalink
Search block: reset size correctly when clearing unit control (#65468)
Browse files Browse the repository at this point in the history
* Search block: reset size correctly when clearing unit control

* Make empty string handling more explicit

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent f8dffcf commit d912271
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,12 @@ export default function SearchEdit( {
}
step={ 1 }
onChange={ ( newWidth ) => {
const filteredWidth =
widthUnit === '%' &&
parseInt( newWidth, 10 ) > 100
? 100
: newWidth;
const parsedNewWidth =
newWidth === ''
? undefined
: parseInt( newWidth, 10 );
setAttributes( {
width: parseInt( filteredWidth, 10 ),
width: parsedNewWidth,
} );
} }
onUnitChange={ ( newUnit ) => {
Expand Down Expand Up @@ -566,7 +565,11 @@ export default function SearchEdit( {

<ResizableBox
size={ {
width: `${ width }${ widthUnit }`,
width:
width === undefined
? 'auto'
: `${ width }${ widthUnit }`,
height: 'auto',
} }
className={ clsx(
'wp-block-search__inside-wrapper',
Expand Down

0 comments on commit d912271

Please sign in to comment.