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
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
@import "./query-pagination-numbers/editor.scss";
@import "./post-featured-image/editor.scss";
@import "./post-comments/editor.scss";
@import "./post-comments-form/editor.scss";

:root .editor-styles-wrapper {
@include background-colors-deprecated();
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-comments-form/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
}
}
},
"editorStyle": "wp-block-post-comments-form",
ockham marked this conversation as resolved.
Show resolved Hide resolved
"style": [
"wp-block-post-comments-form",
"wp-block-buttons",
Expand Down
41 changes: 39 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,10 @@ import {
} from '@wordpress/block-editor';
import { useEntityProp } from '@wordpress/core-data';
import { __, sprintf } from '@wordpress/i18n';
import {
__experimentalUseDisabled as useDisabled,
useInstanceId,
} from '@wordpress/compose';

export default function PostCommentsFormEdit( {
attributes,
Expand All @@ -36,6 +40,10 @@ export default function PostCommentsFormEdit( {

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

const disabledFormRef = useDisabled();

const instanceId = useInstanceId( PostCommentsFormEdit );

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

{ ( 'open' === commentStatus || isInSiteEditor ) &&
__( 'Post Comments Form' ) }
{ ( 'open' === commentStatus || isInSiteEditor ) && (
<div>
<h3>{ __( 'Leave a Reply' ) }</h3>
<form
noValidate
className="comment-form"
ref={ disabledFormRef }
>
<p>
<label htmlFor={ `comment-${ instanceId }` }>
{ __( 'Comment' ) }
</label>
<textarea
id={ `comment-${ instanceId }` }
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
3 changes: 3 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,3 @@
.wp-block-post-comments-form * {
pointer-events: none;
}
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'
);
} );
} );
} );