Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Forms: use placeholder attribute in editor instead of value
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { createHigherOrderComponent, compose } from '@wordpress/compose';
import { addFilter } from '@wordpress/hooks';
import clsx from 'clsx';
import { isEmpty } from 'lodash';
import { useFormStyle } from '../util/form';
import { withSharedFieldAttributes } from '../util/with-shared-field-attributes';
import JetpackFieldControls from './jetpack-field-controls';
Expand All @@ -20,7 +19,7 @@ const JetpackField = props => {
requiredText,
label,
setAttributes,
placeholder,
placeholder = '',
width,
insertBlocksAfter,
type,
Expand All @@ -31,7 +30,7 @@ const JetpackField = props => {
const blockProps = useBlockProps( {
className: clsx( 'jetpack-field', {
'is-selected': isSelected,
'has-placeholder': ! isEmpty( placeholder ),
'has-placeholder': placeholder !== '',
} ),
style: blockStyle,
} );
Expand All @@ -51,8 +50,9 @@ const JetpackField = props => {
className="jetpack-field__input"
onChange={ e => setAttributes( { placeholder: e.target.value } ) }
style={ fieldStyle }
type={ type }
value={ placeholder }
type={ isSelected ? 'text' : type }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that you can enter text placeholders for number input. Otherwise, you could only enter numbers.

The downside is that you might lose input[type="number"] specific styling:

Screenshot 2025-02-27 at 17 02 30

value={ isSelected ? placeholder : '' }
placeholder={ placeholder }
onClick={ event => type === 'file' && event.preventDefault() }
onKeyDown={ event => {
if ( event.defaultPrevented || event.key !== 'Enter' ) {
Expand All @@ -70,7 +70,6 @@ const JetpackField = props => {
setAttributes={ setAttributes }
placeholder={ placeholder }
attributes={ attributes }
hidePlaceholder={ type === 'number' }
/>
</>
);
Expand Down