Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add textarea block
  • Loading branch information
simison committed Dec 9, 2025
commit b7d4eea55f05b584068c46a44cd48372511c9d71
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import JetpackStepContainer from '../form-step-container/index.js';
import JetpackStepDivider from '../form-step-divider/index.js';
import JetpackStepNavigation from '../form-step-navigation/index.js';
import JetpackInput from '../input/index.js';
import JetpackTextarea from '../textarea/index.js';
import JetpackImageOptionInput from '../input-image-option/index.tsx';
import JetpackPhoneInput from '../input-phone/index.js';
import JetpackSliderInput from '../input-range/index.js';
Expand All @@ -40,6 +41,7 @@ export const childBlocks = [
JetpackLabel,
JetpackDropzone,
JetpackInput,
JetpackTextarea,
JetpackOption,
JetpackOptions,
JetpackCheckboxField,
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/blocks/field-textarea/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function TextareaFieldEdit( props ) {
const template = useMemo( () => {
return [
[ 'jetpack/label', { label: __( 'Message', 'jetpack-forms' ), requiredIndicator } ],
[ 'jetpack/input', { type: 'textarea' } ],
[ 'jetpack/textarea' ],
];
}, [ requiredIndicator ] );

Expand Down
5 changes: 1 addition & 4 deletions projects/packages/forms/src/blocks/field-textarea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ const settings = {
},
},
{
name: 'jetpack/input',
attributes: {
type: 'textarea',
},
name: 'jetpack/textarea',
},
],
},
Expand Down
47 changes: 47 additions & 0 deletions projects/packages/forms/src/blocks/textarea/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { useCallback } from '@wordpress/element';
import { clsx } from 'clsx';
import { useSyncedAttributes } from '../shared/hooks/use-synced-attributes.js';
import useVariationStyleProperties from '../shared/hooks/use-variation-style-properties.js';

const SYNCED_ATTRIBUTE_KEYS = [
'backgroundColor',
'borderColor',
'fontFamily',
'fontSize',
'style',
'textColor',
];

const TextareaEdit = ( { attributes, clientId, isSelected, name, setAttributes, context } ) => {
const { 'jetpack/field-share-attributes': isSynced } = context;
useSyncedAttributes( name, isSynced, SYNCED_ATTRIBUTE_KEYS, attributes, setAttributes );
const { placeholder } = attributes;
const variationProps = useVariationStyleProperties( {
clientId,
inputBlockName: name,
inputBlockAttributes: attributes,
} );
const blockProps = useBlockProps( {
className: 'jetpack-field__textarea',
style: variationProps?.cssVars,
} );

const onChange = useCallback(
event => {
setAttributes( { placeholder: event.target.value } );
},
[ setAttributes ]
);

return (
<textarea
{ ...blockProps }
onChange={ onChange }
value={ isSelected ? placeholder : '' }
placeholder={ placeholder }
/>
);
};

export default TextareaEdit;
70 changes: 70 additions & 0 deletions projects/packages/forms/src/blocks/textarea/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Path } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import renderMaterialIcon from '../shared/components/render-material-icon.js';
import edit from './edit.js';
import save from './save.js';

const name = 'textarea';
const settings = {
apiVersion: 3,
title: __( 'Textarea', 'jetpack-forms' ),
description: __( 'A textarea for a form field', 'jetpack-forms' ),
category: 'contact-form',
icon: {
src: renderMaterialIcon(
<Path d="M20 5H4V6.5H20V5ZM5.5 11.5H18.5V18.5H5.5V11.5ZM20 20V10H4V20H20Z" />
),
},
parent: [ 'jetpack/field-textarea' ],
usesContext: [ 'jetpack/field-share-attributes' ],
supports: {
reusable: false,
html: false,
color: {
text: true,
background: true,
gradients: false,
},
__experimentalBorder: {
color: true,
radius: true,
style: true,
width: true,
__experimentalDefaultControls: {
color: true,
radius: true,
style: true,
width: true,
},
},
dimensions: {
minHeight: true,
},
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontFamily: true,
__experimentalFontWeight: true,
__experimentalFontStyle: true,
__experimentalTextTransform: true,
__experimentalTextDecoration: true,
__experimentalLetterSpacing: true,
__experimentalDefaultControls: {
fontSize: true,
},
},
},
attributes: {
placeholder: {
type: 'string',
default: '',
},
},
edit,
save,
};

export default {
name,
settings,
};
1 change: 1 addition & 0 deletions projects/packages/forms/src/blocks/textarea/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => null;