Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Comments Form: Add "proper" visual representation in the editor #40368

Merged
merged 10 commits into from
Apr 22, 2022
37 changes: 35 additions & 2 deletions packages/block-library/src/post-comments-form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@wordpress/block-editor';
import { useEntityProp } from '@wordpress/core-data';
import { __, sprintf } from '@wordpress/i18n';
import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';

export default function PostCommentsFormEdit( {
attributes,
Expand All @@ -36,6 +37,8 @@ export default function PostCommentsFormEdit( {

const isInSiteEditor = postType === undefined || postId === undefined;

const disabledFormRef = useDisabled();

return (
<>
<BlockControls group="block">
Expand Down Expand Up @@ -67,8 +70,38 @@ export default function PostCommentsFormEdit( {
</Warning>
) }

{ ( 'open' === commentStatus || isInSiteEditor ) &&
__( 'Post Comments Form' ) }
{ ( 'open' === commentStatus || isInSiteEditor ) && (
<div className="wp-block-post-comments-form">
michalczaplinski marked this conversation as resolved.
Show resolved Hide resolved
<h3>{ __( 'Leave a Reply' ) }</h3>
<form
noValidate
className="comment-form"
ref={ disabledFormRef }
>
<p>
<label htmlFor="comment">
{ __( 'Comment' ) }
</label>
<textarea
/* eslint-disable-next-line no-restricted-syntax */
id="comment"
name="comment"
cols="45"
rows="8"
/>
</p>
<p>
<input
name="submit"
className="submit wp-block-button__link"
label={ __( 'Post Comment' ) }
value={ __( 'Post Comment' ) }
readOnly
/>
</p>
</form>
</div>
) }
</div>
</>
);
Expand Down
25 changes: 25 additions & 0 deletions packages/block-library/src/post-comments-form/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.wp-block-post-comments-form {
textarea {
padding: calc(0.667em + 2px);
border: 1px solid $gray-600;
font-size: 1em;
font-family: inherit;
}

.comment-form {
textarea,
label {
display: block;
margin-bottom: 0.25em;
}
}

input[name="submit"] {
border: none;
box-shadow: none;
cursor: pointer;
display: inline-block;
text-align: center;
overflow-wrap: break-word;
}
}
michalczaplinski marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* WordPress dependencies
*/
import {
insertBlock,
activateTheme,
setOption,
visitSiteEditor,
openSiteEditorNavigationPanel,
navigateSiteEditorBackToRoot,
deleteAllTemplates,
canvas,
} from '@wordpress/e2e-test-utils';

describe( 'Post Comments Form', () => {
beforeAll( async () => {
await activateTheme( 'emptytheme' );
await deleteAllTemplates( 'wp_template' );
} );

describe( 'placeholder', () => {
it( 'displays in site editor even when comments are closed by default', async () => {
await setOption( 'default_comment_status', 'closed' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be reset to the previous value again after the test run has complete?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should, so I've updated the test in this PR.


// Navigate to "Singular" post template
await visitSiteEditor();
await openSiteEditorNavigationPanel();
await navigateSiteEditorBackToRoot();
await expect( page ).toClick(
'.components-navigation__item-title',
{ text: /templates/i }
);
await expect( page ).toClick( '.components-heading > a', {
text: /singular/i,
} );

// Insert post comments form
await insertBlock( 'Post Comments Form' );

// Ensure the placeholder is there
await expect( canvas() ).toMatchElement(
'.wp-block-post-comments-form .comment-form'
);
} );
} );
} );