-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Spacer block: stop using UnitControl's deprecated unit prop
#39513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,10 @@ import { | |
| PanelBody, | ||
| __experimentalUseCustomUnits as useCustomUnits, | ||
| __experimentalUnitControl as UnitControl, | ||
| __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue, | ||
| } from '@wordpress/components'; | ||
| import { useInstanceId } from '@wordpress/compose'; | ||
| import { useState } from '@wordpress/element'; | ||
| import { useState, useMemo } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
|
|
@@ -51,7 +52,15 @@ function DimensionInput( { label, onChange, isResizing, value = '' } ) { | |
| } | ||
| }; | ||
|
|
||
| const inputValue = temporaryInput !== null ? temporaryInput : value; | ||
| const computedValue = useMemo( () => { | ||
|
||
| const inputValue = temporaryInput !== null ? temporaryInput : value; | ||
| const [ parsedQuantity, parsedUnit ] = parseQuantityAndUnitFromRawValue( | ||
| inputValue | ||
| ); | ||
|
|
||
| // Force the unit to update to `px` when the Spacer is being resized. | ||
| return [ parsedQuantity, isResizing ? 'px' : parsedUnit ].join( '' ); | ||
| }, [ isResizing, temporaryInput, value ] ); | ||
|
|
||
| return ( | ||
| <BaseControl label={ label } id={ inputId }> | ||
|
|
@@ -63,10 +72,8 @@ function DimensionInput( { label, onChange, isResizing, value = '' } ) { | |
| onBlur={ handleOnBlur } | ||
| onChange={ handleOnChange } | ||
| style={ { maxWidth: 80 } } | ||
| value={ inputValue } | ||
| value={ computedValue } | ||
| units={ units } | ||
| // Force the unit to update to `px` when the Spacer is being resized. | ||
| unit={ isResizing ? 'px' : undefined } | ||
| /> | ||
| </BaseControl> | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.