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
34 changes: 19 additions & 15 deletions packages/block-library/src/form-input/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ function InputFieldBlock( { attributes, setAttributes, className } ) {
'Affects the "name" attribute of the input element, and is used as a name for the form submission results.'
) }
/>
{ 'hidden' === type && (
<TextControl
__next40pxDefaultSize
autoComplete="off"
label={ __( 'Value' ) }
value={ value }
onChange={ ( newVal ) =>
setAttributes( { value: newVal } )
}
help={ __(
'Sets the stored value for this hidden field.'
) }
/>
) }
</InspectorControls>
</>
);
Expand All @@ -133,23 +147,13 @@ function InputFieldBlock( { attributes, setAttributes, className } ) {

if ( 'hidden' === type ) {
return (
<>
<div { ...blockProps }>
{ controls }
<input
type="hidden"
className={ clsx(
className,
'wp-block-form-input__input',
colorProps.className,
borderProps.className
) }
aria-label={ __( 'Value' ) }
value={ value }
onChange={ ( event ) =>
setAttributes( { value: event.target.value } )
}
<span
className="wp-block-form-input__label is-input-hidden"
data-message={ __( 'Hidden field' ) }
/>
</>
</div>
);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/block-library/src/form-input/editor.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
.wp-block-form-input {
.is-input-hidden {
display: flex;
position: relative;
font-size: 0.85em;
opacity: 0.3;
border: 1px dashed;
padding: 0.5em;
box-sizing: border-box;
background: repeating-linear-gradient(45deg, transparent, transparent 5px, currentColor 5px, currentColor 6px);
justify-content: center;
align-items: center;

input[type="text"] {
background: transparent;
&::after {
content: attr(data-message);
}
}
&.is-selected {
.is-input-hidden {
opacity: 1;
background: none;

input[type="text"] {
background: unset;
}
}
}
}
10 changes: 10 additions & 0 deletions packages/block-library/src/form-input/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ const variations = [
scope: [ 'inserter', 'transform' ],
isActive: ( blockAttributes ) => blockAttributes?.type === 'number',
},
{
name: 'hidden',
title: __( 'Hidden Input' ),
icon: 'visibility',
description: __( 'A hidden input field.' ),
attributes: { type: 'hidden' },
isDefault: true,
scope: [ 'inserter', 'transform' ],
isActive: ( blockAttributes ) => blockAttributes?.type === 'hidden',
},
];

export default variations;
Loading