Skip to content

Commit ff6b4dd

Browse files
authored
Forms: Make file upload field block available in beta and refine its behavior (#41586)
1 parent 260afda commit ff6b4dd

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Forms: Refine file upload field block to use WordPress upload icon and follow consistent field patterns. Make the block available in beta.

projects/packages/forms/src/blocks/contact-form/child-blocks.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { InnerBlocks } from '@wordpress/block-editor';
22
import { createBlock } from '@wordpress/blocks';
33
import { Path, Icon } from '@wordpress/components';
44
import { __, _x } from '@wordpress/i18n';
5-
import { globe, envelope, mobile } from '@wordpress/icons';
5+
import { globe, envelope, mobile, upload } from '@wordpress/icons';
66
import { filter, isEmpty, map, startsWith, trim } from 'lodash';
77
import JetpackField from './components/jetpack-field';
88
import JetpackFieldCheckbox from './components/jetpack-field-checkbox';
@@ -521,9 +521,7 @@ export const childBlocks = [
521521
description: __( 'Allow visitors to upload files through your form.', 'jetpack-forms' ),
522522
icon: {
523523
foreground: getIconColor(),
524-
src: renderMaterialIcon(
525-
<Path d="M11 14.5V6.33L8.5 8.83L7.67 8L12 3.67L16.33 8L15.5 8.83L13 6.33V14.5H11ZM12 20.33L7.67 16L8.5 15.17L11 17.67V15.5H13V17.67L15.5 15.17L16.33 16L12 20.33Z" />
526-
),
524+
src: <Icon icon={ upload } />,
527525
},
528526
edit: editField( 'file' ),
529527
attributes: {
@@ -538,7 +536,7 @@ export const childBlocks = [
538536
default: '',
539537
},
540538
},
541-
isExperimental: true,
539+
isBeta: true,
542540
},
543541
},
544542
{

projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ public static function register_child_blocks() {
162162
);
163163

164164
$blocks_variation = apply_filters( 'jetpack_blocks_variation', \Automattic\Jetpack\Constants::get_constant( 'JETPACK_BLOCKS_VARIATION' ) );
165-
if ( 'experimental' === $blocks_variation ) {
166-
self::register_experimental_blocks();
165+
if ( 'beta' === $blocks_variation ) {
166+
self::register_beta_blocks();
167167
}
168168
}
169169

170170
/**
171-
* Register experimental blocks
171+
* Register beta blocks
172172
*/
173-
private static function register_experimental_blocks() {
173+
private static function register_beta_blocks() {
174174
Blocks::jetpack_register_block(
175175
'jetpack/field-file',
176176
array(

projects/packages/forms/src/blocks/contact-form/components/jetpack-field.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,20 @@ const JetpackField = props => {
4747
setAttributes={ setAttributes }
4848
style={ formStyle }
4949
/>
50-
{ type === 'file' ? (
51-
<input type="file" className="jetpack-field__input" />
52-
) : (
53-
<input
54-
className="jetpack-field__input"
55-
onChange={ e => setAttributes( { placeholder: e.target.value } ) }
56-
style={ fieldStyle }
57-
type="text"
58-
value={ placeholder }
59-
onKeyDown={ event => {
60-
if ( event.defaultPrevented || event.key !== 'Enter' ) {
61-
return;
62-
}
63-
insertBlocksAfter( createBlock( getDefaultBlockName() ) );
64-
} }
65-
/>
66-
) }
50+
<input
51+
className="jetpack-field__input"
52+
onChange={ e => setAttributes( { placeholder: e.target.value } ) }
53+
style={ fieldStyle }
54+
type={ type }
55+
value={ placeholder }
56+
onClick={ event => type === 'file' && event.preventDefault() }
57+
onKeyDown={ event => {
58+
if ( event.defaultPrevented || event.key !== 'Enter' ) {
59+
return;
60+
}
61+
insertBlocksAfter( createBlock( getDefaultBlockName() ) );
62+
} }
63+
/>
6764
</div>
6865

6966
<JetpackFieldControls

projects/packages/forms/src/blocks/contact-form/util/register-jetpack-block.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { addFilter } from '@wordpress/hooks';
1919
export default function registerJetpackBlock( name, settings, childBlocks = [], prefix = true ) {
2020
const { available, details, unavailableReason } = getJetpackExtensionAvailability( name );
2121
const jetpackData = getJetpackData();
22-
const isExperimental = jetpackData?.blocks_variation === 'experimental';
22+
const isBeta = jetpackData?.blocks_variation === 'beta';
2323

2424
const requiredPlan = requiresPaidPlan( unavailableReason, details );
2525
const jpPrefix = prefix ? 'jetpack/' : '';
@@ -48,8 +48,8 @@ export default function registerJetpackBlock( name, settings, childBlocks = [],
4848
// Register child blocks. Using `registerBlockType()` directly avoids availability checks -- if
4949
// their parent is available, we register them all, without checking for their individual availability.
5050
childBlocks.forEach( childBlock => {
51-
// Skip experimental blocks unless experimental variation is enabled
52-
if ( childBlock.settings?.isExperimental && ! isExperimental ) {
51+
// Skip beta blocks unless beta variation is enabled
52+
if ( childBlock.settings?.isBeta && ! isBeta ) {
5353
return;
5454
}
5555
registerBlockType( jpPrefix + childBlock.name, childBlock.settings );

0 commit comments

Comments
 (0)