Skip to content

Commit 0ca873f

Browse files
committed
Allow writing placeholder using input value
1 parent 3018527 commit 0ca873f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

+4-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,8 @@ const JetpackField = props => {
5150
className="jetpack-field__input"
5251
onChange={ e => setAttributes( { placeholder: e.target.value } ) }
5352
style={ fieldStyle }
54-
type={ type }
55-
value=""
53+
type={ isSelected ? 'text' : type }
54+
value={ isSelected ? placeholder : '' }
5655
placeholder={ placeholder }
5756
onClick={ event => type === 'file' && event.preventDefault() }
5857
onKeyDown={ event => {
@@ -71,7 +70,6 @@ const JetpackField = props => {
7170
setAttributes={ setAttributes }
7271
placeholder={ placeholder }
7372
attributes={ attributes }
74-
hidePlaceholder={ type === 'number' }
7573
/>
7674
</>
7775
);

0 commit comments

Comments
 (0)