diff --git a/projects/packages/forms/changelog/update-forms-text-field-height-input b/projects/packages/forms/changelog/update-forms-text-field-height-input new file mode 100644 index 000000000000..9c99b033b531 --- /dev/null +++ b/projects/packages/forms/changelog/update-forms-text-field-height-input @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Forms: allow resizing height of multi line text field diff --git a/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php b/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php index 81b90d613a8f..a39f8925d324 100644 --- a/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php +++ b/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php @@ -144,6 +144,11 @@ public static function register_child_blocks() { 'color' => '.wp-block-jetpack-input, .is-style-outlined .notched-label:has(+ .wp-block-jetpack-input) > *,.is-style-outlined .wp-block-jetpack-input + .notched-label > *, .is-style-outlined .wp-block-jetpack-field-select .notched-label > *', ), 'uses_context' => array( 'jetpack/field-default-value' ), + 'attributes' => array( + 'height' => array( + 'type' => 'string', + ), + ), ) ); Blocks::jetpack_register_block( diff --git a/projects/packages/forms/src/blocks/input/edit.js b/projects/packages/forms/src/blocks/input/edit.js index a76b42194af9..2f6f7cab530b 100644 --- a/projects/packages/forms/src/blocks/input/edit.js +++ b/projects/packages/forms/src/blocks/input/edit.js @@ -1,5 +1,15 @@ -import { InspectorControls, RichText, useBlockProps } from '@wordpress/block-editor'; -import { PanelBody, __experimentalNumberControl as NumberControl } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis +import { + InspectorControls, + RichText, + store as blockEditorStore, + useBlockProps, +} from '@wordpress/block-editor'; +import { + __experimentalNumberControl as NumberControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis + PanelBody, + ResizableBox, +} from '@wordpress/components'; +import { useSelect } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { clsx } from 'clsx'; @@ -29,10 +39,18 @@ const getInputClass = type => { return 'jetpack-field__input'; }; -const InputEdit = ( { attributes, clientId, isSelected, name, setAttributes, context } ) => { +const InputEdit = ( { + attributes, + clientId, + context, + isSelected, + name, + setAttributes, + toggleSelection, +} ) => { const { 'jetpack/field-share-attributes': isSynced } = context; useSyncedAttributes( name, isSynced, SYNCED_ATTRIBUTE_KEYS, attributes, setAttributes ); - const { max, min, placeholder, type } = attributes; + const { max, min, height, placeholder, type } = attributes; const variationProps = useVariationStyleProperties( { clientId, inputBlockName: name, @@ -44,6 +62,17 @@ const InputEdit = ( { attributes, clientId, isSelected, name, setAttributes, con const blockProps = useBlockProps( { className, style: variationProps?.cssVars } ); const onKeyDown = useInsertAfterOnEnterKeyDown( clientId ); + // Check if the parent block (e.g. textarea-field) is selected + const isParentSelected = useSelect( + select => { + const { getBlockRootClientId, getSelectedBlockClientId } = select( blockEditorStore ); + const parentClientId = getBlockRootClientId( clientId ); + const selectedBlockClientId = getSelectedBlockClientId(); + return parentClientId && parentClientId === selectedBlockClientId; + }, + [ clientId ] + ); + const onChange = useCallback( event => { if ( type !== 'time' ) { @@ -68,13 +97,39 @@ const InputEdit = ( { attributes, clientId, isSelected, name, setAttributes, con } if ( type === 'textarea' ) { + const currentHeight = height + ? parseInt( typeof height === 'string' ? height.replace( 'px', '' ) : height, 10 ) || 200 + : 200; + return ( -