diff --git a/packages/block-library/src/cover/edit/inspector-controls.js b/packages/block-library/src/cover/edit/inspector-controls.js index 0b05a004cd06e0..cf6d9a6486a0e5 100644 --- a/packages/block-library/src/cover/edit/inspector-controls.js +++ b/packages/block-library/src/cover/edit/inspector-controls.js @@ -12,18 +12,15 @@ import { TextareaControl, ToggleControl, SelectControl, - __experimentalUseCustomUnits as useCustomUnits, __experimentalToolsPanelItem as ToolsPanelItem, - __experimentalUnitControl as UnitControl, __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue, } from '@wordpress/components'; -import { useInstanceId } from '@wordpress/compose'; import { InspectorControls, - useSettings, __experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown, __experimentalUseGradient, __experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients, + HeightControl, privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; @@ -31,7 +28,7 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import { COVER_MIN_HEIGHT, mediaPosition } from '../shared'; +import { mediaPosition } from '../shared'; import { unlock } from '../../lock-unlock'; const { cleanEmptyObject } = unlock( blockEditorPrivateApis ); @@ -42,26 +39,19 @@ function CoverHeightInput( { unit = 'px', value = '', } ) { - const instanceId = useInstanceId( UnitControl ); - const inputId = `block-cover-height-input-${ instanceId }`; - const isPx = unit === 'px'; - - const [ availableUnits ] = useSettings( 'spacing.units' ); - const units = useCustomUnits( { - availableUnits: availableUnits || [ 'px', 'em', 'rem', 'vw', 'vh' ], - defaultValues: { px: 430, '%': 20, em: 20, rem: 20, vw: 20, vh: 50 }, - } ); - const handleOnChange = ( unprocessedValue ) => { - const inputValue = - unprocessedValue !== '' - ? parseFloat( unprocessedValue ) - : undefined; + const parsedQuantityAndUnit = + parseQuantityAndUnitFromRawValue( unprocessedValue ); + const currentValue = parsedQuantityAndUnit[ 0 ]; - if ( isNaN( inputValue ) && inputValue !== undefined ) { + if ( isNaN( currentValue ) && currentValue !== undefined ) { return; } - onChange( inputValue ); + + const currentUnit = parsedQuantityAndUnit[ 1 ]; + + onUnitChange( currentUnit ); + onChange( currentValue ); }; const computedValue = useMemo( () => { @@ -69,19 +59,11 @@ function CoverHeightInput( { return [ parsedQuantity, unit ].join( '' ); }, [ unit, value ] ); - const min = isPx ? COVER_MIN_HEIGHT : 0; - return ( - ); } diff --git a/packages/block-library/src/cover/test/edit.js b/packages/block-library/src/cover/test/edit.js index ab99d3c555e3bc..5cb5aeed69d690 100644 --- a/packages/block-library/src/cover/test/edit.js +++ b/packages/block-library/src/cover/test/edit.js @@ -371,13 +371,13 @@ describe( 'Cover block', () => { name: 'Styles', } ) ); - await userEvent.clear( - screen.getByLabelText( 'Minimum height of cover' ) - ); - await userEvent.type( - screen.getByLabelText( 'Minimum height of cover' ), - '300' - ); + + const heightControl = screen.getByRole( 'spinbutton', { + name: 'Minimum height', + } ); + + await userEvent.clear( heightControl ); + await userEvent.type( heightControl, '300' ); expect( screen.getByLabelText( 'Block: Cover' ) ).toHaveStyle( 'min-height: 300px;' diff --git a/test/e2e/specs/editor/blocks/cover.spec.js b/test/e2e/specs/editor/blocks/cover.spec.js index fa5103ebaa4eeb..56c47fef9c0cca 100644 --- a/test/e2e/specs/editor/blocks/cover.spec.js +++ b/test/e2e/specs/editor/blocks/cover.spec.js @@ -156,9 +156,9 @@ test.describe( 'Cover', () => { .getByRole( 'tab', { name: 'Styles' } ) .click(); - // Ensure there the default value for the minimum height of cover is undefined. + // Ensure there the default value for the Minimum height is undefined. const defaultHeightValue = await coverBlockEditorSettings - .getByLabel( 'Minimum height of cover' ) + .getByRole( 'spinbutton', { name: 'Minimum height' } ) .inputValue(); expect( defaultHeightValue ).toBeFalsy();