Skip to content

Commit 9d31d55

Browse files
authored
Forms: use a placeholder attribute in the editor instead of value (#41712)
1 parent 78d3239 commit 9d31d55

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Forms: use placeholder attribute in editor instead of value

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
33
import { createHigherOrderComponent, compose } from '@wordpress/compose';
44
import { addFilter } from '@wordpress/hooks';
55
import clsx from 'clsx';
6-
import { isEmpty } from 'lodash';
76
import { useFormStyle } from '../util/form';
87
import { withSharedFieldAttributes } from '../util/with-shared-field-attributes';
98
import JetpackFieldControls from './jetpack-field-controls';
@@ -20,7 +19,7 @@ const JetpackField = props => {
2019
requiredText,
2120
label,
2221
setAttributes,
23-
placeholder,
22+
placeholder = '',
2423
width,
2524
insertBlocksAfter,
2625
type,
@@ -31,7 +30,7 @@ const JetpackField = props => {
3130
const blockProps = useBlockProps( {
3231
className: clsx( 'jetpack-field', {
3332
'is-selected': isSelected,
34-
'has-placeholder': ! isEmpty( placeholder ),
33+
'has-placeholder': placeholder !== '',
3534
} ),
3635
style: blockStyle,
3736
} );
@@ -51,8 +50,9 @@ const JetpackField = props => {
5150
className="jetpack-field__input"
5251
onChange={ e => setAttributes( { placeholder: e.target.value } ) }
5352
style={ fieldStyle }
54-
type={ type }
55-
value={ placeholder }
53+
type={ isSelected ? 'text' : type }
54+
value={ isSelected ? placeholder : '' }
55+
placeholder={ placeholder }
5656
onClick={ event => type === 'file' && event.preventDefault() }
5757
onKeyDown={ event => {
5858
if ( event.defaultPrevented || event.key !== 'Enter' ) {
@@ -70,7 +70,6 @@ const JetpackField = props => {
7070
setAttributes={ setAttributes }
7171
placeholder={ placeholder }
7272
attributes={ attributes }
73-
hidePlaceholder={ type === 'number' }
7473
/>
7574
</>
7675
);

0 commit comments

Comments
 (0)