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

Add placeholder to Post Comments block #40484

Merged
merged 6 commits into from
Apr 21, 2022

Conversation

luisherranz
Copy link
Member

@luisherranz luisherranz commented Apr 20, 2022

What?

This PR adds a placeholder in the Editor for the Post Comments block. It includes:

  • A warning at the top with the text:

    This is just a placeholder, not a real comment. The final styling may differ because it also depends on the current theme. For better compatibility with the Block Editor, please consider replacing this block with the "Comments Query Loop" block.

  • The navigation links

  • A comment example, including an avatar, author name, date, content, and reply link.

  • The reply form.

Why?

Before this, the Post Comments blocked rendered:

  • Site Editor: A warning with the text Post comments block: no post found.
  • Post Editor:
    • Post with comments: A loop of the raw HTML of all the comments, unnested and unstyled.
    • Post without comments: The text No comments.

None of those are especially useful, considering the only action users can perform in this block is to configure its style.

How?

I've added the default comments markup. The only dynamic parts are the post title and the user name (to simulate the reply form message).

I've used Gutenberg's <Warning> component for the warning. I'm not a big fan of how it looks like in the UI, but I think it's out of the scope of this PR to address that.

I acknowledge that this type of placeholder is far from ideal, but @DAreRodz and I analyzed the other possibilities, and we concluded that it was the least bad option. The other possibilities we considered were:

  • Using <ServerSideRender> component.

    Executing comment_template() didn't work within a REST API call (/wp/v2/block-renderer/) because it doesn't have a post context.

    Even if that could be solved, the result wouldn't faithfully represent the frontend because:

    • The comment-related styles from the theme and plugins would be missing.
    • It would not work in the site editor because we can't inject dummy data to the comment_template() function.
  • Looping over the real comments in the Editor to reproduce the final HTML as faithfully as possible.

    Replicating the logic of the comments is not trivial (as we've seen in the Comments Query Loop blocks).

    Also, the result wouldn't faithfully represent the frontend because:

    • The markup modifications of the theme and plugins would be missing.
    • The comment-related styles from the theme and plugins would be missing.

So at the end, and considering that this is a temporary block that should be removed once the Comments Query Loop and the Comments Form blocks are mature enough, we decided to add the default comments markup so the user can get a notion of the styles, and a warning to prevent confusion.

Testing Instructions

Site Editor:

  1. Add the Post Comments block to a template.
  2. Look that the placeholder looks as expected.
  3. Test that the styling options work.

Post Editor:

  1. Add the Post Comments block to a post.
  2. Look that the placeholder looks as expected.
  3. Test that the styling options work.

Screenshots or screencast

https://www.loom.com/share/91b518264de84e75a7c3a64e283ee0c2

@luisherranz luisherranz added the [Block] Comments (legacy) The legacy mode of the Comments block (formerly known as Post Comments) label Apr 20, 2022
@luisherranz luisherranz requested a review from ajitbohra as a code owner April 20, 2022 16:16
@luisherranz luisherranz self-assigned this Apr 20, 2022
@github-actions
Copy link

github-actions bot commented Apr 20, 2022

Size Change: -547 B (0%)

Total Size: 1.23 MB

Filename Size Change
build/admin-manifest/index.min.js 0 B -1.24 kB (removed) 🏆
build/block-editor/index.min.js 150 kB -47 B (0%)
build/block-library/blocks/post-comments/style-rtl.css 511 B -10 B (-2%)
build/block-library/blocks/post-comments/style.css 511 B -10 B (-2%)
build/block-library/editor-rtl.css 10.2 kB +13 B (0%)
build/block-library/editor.css 10.2 kB +12 B (0%)
build/block-library/index.min.js 177 kB +1.07 kB (+1%)
build/block-library/style-rtl.css 11.5 kB -17 B (0%)
build/block-library/style.css 11.5 kB -17 B (0%)
build/edit-navigation/style-rtl.css 4.05 kB +6 B (0%)
build/edit-navigation/style.css 4.05 kB +6 B (0%)
build/edit-post/style-rtl.css 7.11 kB -78 B (-1%)
build/edit-post/style.css 7.11 kB -79 B (-1%)
build/edit-site/style-rtl.css 7.95 kB -86 B (-1%)
build/edit-site/style.css 7.93 kB -89 B (-1%)
build/edit-widgets/style-rtl.css 4.41 kB +9 B (0%)
build/edit-widgets/style.css 4.4 kB +10 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.77 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 6.51 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 15.1 kB
build/block-editor/style.css 15.1 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 59 B
build/block-library/blocks/avatar/style.css 59 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 445 B
build/block-library/blocks/button/editor.css 445 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 103 B
build/block-library/blocks/code/style.css 103 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-query-loop/editor-rtl.css 95 B
build/block-library/blocks/comments-query-loop/editor.css 95 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.56 kB
build/block-library/blocks/cover/style.css 1.56 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 961 B
build/block-library/blocks/gallery/editor.css 964 B
build/block-library/blocks/gallery/style-rtl.css 1.51 kB
build/block-library/blocks/gallery/style.css 1.51 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 333 B
build/block-library/blocks/group/editor.css 333 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 529 B
build/block-library/blocks/image/style.css 535 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 447 B
build/block-library/blocks/latest-posts/style.css 446 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 708 B
build/block-library/blocks/navigation-link/editor.css 706 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 375 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.93 kB
build/block-library/blocks/navigation/style.css 1.92 kB
build/block-library/blocks/navigation/view-modal.min.js 2.65 kB
build/block-library/blocks/navigation/view.min.js 395 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 363 B
build/block-library/blocks/page-list/editor.css 363 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 260 B
build/block-library/blocks/paragraph/style.css 260 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 521 B
build/block-library/blocks/post-comments-form/style.css 521 B
build/block-library/blocks/post-comments/editor-rtl.css 77 B
build/block-library/blocks/post-comments/editor.css 77 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 323 B
build/block-library/blocks/post-template/style.css 323 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 370 B
build/block-library/blocks/pullquote/style.css 370 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 369 B
build/block-library/blocks/query/editor.css 369 B
build/block-library/blocks/quote/style-rtl.css 213 B
build/block-library/blocks/quote/style.css 213 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 140 B
build/block-library/blocks/separator/editor.css 140 B
build/block-library/blocks/separator/style-rtl.css 233 B
build/block-library/blocks/separator/style.css 233 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 759 B
build/block-library/blocks/site-logo/editor.css 759 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 504 B
build/block-library/blocks/table/editor.css 504 B
build/block-library/blocks/table/style-rtl.css 625 B
build/block-library/blocks/table/style.css 625 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 149 B
build/block-library/blocks/template-part/editor.css 149 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 993 B
build/block-library/common.css 990 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/theme-rtl.css 689 B
build/block-library/theme.css 694 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 47 kB
build/components/index.min.js 223 kB
build/components/style-rtl.css 15 kB
build/components/style.css 15 kB
build/compose/index.min.js 11.2 kB
build/core-data/index.min.js 14.5 kB
build/customize-widgets/index.min.js 11 kB
build/customize-widgets/style-rtl.css 1.39 kB
build/customize-widgets/style.css 1.39 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 8.65 kB
build/date/index.min.js 32 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.58 kB
build/edit-navigation/index.min.js 15.8 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 30.1 kB
build/edit-site/index.min.js 47.5 kB
build/edit-widgets/index.min.js 16.3 kB
build/editor/index.min.js 38.5 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.71 kB
build/element/index.min.js 4.29 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 6.62 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.83 kB
build/keycodes/index.min.js 1.41 kB
build/list-reusable-blocks/index.min.js 1.75 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.94 kB
build/notices/index.min.js 957 B
build/nux/index.min.js 2.12 kB
build/nux/style-rtl.css 751 B
build/nux/style.css 749 B
build/plugins/index.min.js 1.98 kB
build/preferences/index.min.js 1.2 kB
build/primitives/index.min.js 949 B
build/priority-queue/index.min.js 628 B
build/react-i18n/index.min.js 704 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.69 kB
build/reusable-blocks/index.min.js 2.24 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.2 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.52 kB
build/token-list/index.min.js 668 B
build/url/index.min.js 1.99 kB
build/vendors/react-dom.min.js 38.5 kB
build/vendors/react.min.js 4.34 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.21 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.07 kB

compressed-size-action

Copy link
Contributor

@michalczaplinski michalczaplinski left a comment

Choose a reason for hiding this comment

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

Nice job, I think it looks great already! 👍 I only have some minor comments here

packages/block-library/src/post-comments/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/post-comments/edit.js Outdated Show resolved Hide resolved
Copy link
Contributor

@SantosGuillamot SantosGuillamot left a comment

Choose a reason for hiding this comment

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

It looks great to me! 🙂

Would it make sense to add some css to prevent interactivity in the editor? I mean, as the links don't work and the textarea, for example, doesn't accept input, maybe we could prevent the clicks there with something like:

.wp-block-post-comments * {
    pointer-events: none;
}

@luisherranz
Copy link
Member Author

Thanks, Mario. I'll add that CSS 🙂

@luisherranz luisherranz marked this pull request as draft April 21, 2022 08:03
@cbravobernal
Copy link
Contributor

Maybe adding disabled to the input would be a better option. I'm not sure if with pointer-events: none, iOS Voiceover seems that cannot access the inner parts of the elements of the form to see what you are going to render.

@DAreRodz
Copy link
Contributor

DAreRodz commented Apr 21, 2022

For me, this looks great so far. Thaks for taking care of this, @luisherranz! 🙌

PS: it's a bit weird to see the warning message styles changing when you modify, e.g., the comments color or font size. 😅 Not sure if we could/should do something regarding that.

@luisherranz
Copy link
Member Author

luisherranz commented Apr 21, 2022

PS: it's a bit weird to see the warning message styles changing when you modify, e.g., the comments color or font size. 😅 Not sure if we could/should do something regarding that.

Yes, that should be definitely fixed, but probably out of the scope of this PR.

EDIT: I've opened a separate issue for that #40536.

Maybe adding disabled to the input would be a better option.

I already added readOnly because I saw @michalczaplinski did it here d7650b2. If disabled is also recommended let me know.

EDIT: Removed in favor of useDisabled as described in #40484 (comment).


I saw in @michalczaplinski's PR (#40368) a bit of logic to show different warning messages if the post you're editing doesn't support comments for some reason, so I've added it here as well. It took it a bit further, though.

@michalczaplinski could you please check it out, let me know what you think, and maybe if you like the approach, merge this and reuse the same logic for your block (create a hook that can be shared, or something like that).

This is the flow I've used:

Excalidraw

And this is the video explanation:

https://www.loom.com/share/339af4d5ee974758a3c8f6b491f2bf0d

@luisherranz luisherranz marked this pull request as ready for review April 21, 2022 10:47
@ockham
Copy link
Contributor

ockham commented Apr 21, 2022

Thanks a lot @luisherranz, this is looking great!

@priethor has asked over at #40368 for some design feedback on how to make it even clearer that these placeholders aren't really editable, to which @jasmussen kindly replied.

Would it be possible to apply Joen's suggestions to this PR as well? 😊 🙏

@luisherranz
Copy link
Member Author

Would it be possible to apply Joen's suggestions to this PR as well?

I'm on it 🙂

Copy link
Contributor

@cbravobernal cbravobernal left a comment

Choose a reason for hiding this comment

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

LGTM! But still have some doubts if how accessible is this block for screen readers.

@cbravobernal cbravobernal added the Needs Accessibility Feedback Need input from accessibility label Apr 21, 2022
Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

Thanks @luisherranz! This is looking great 👍

Let's merge this as-is.

Some ideas for follow-ups:

  • We might be able to figure out the CSS quirks you mentioned in your Loom in a follow-up.
  • I also don't know how this is going to work in terms of a11y. Maybe we can have someone who has a better grasp of a11y review this, so we can fix it in a follow-up.
  • We'll go with the Warning for now (even though this is likely not an established UX pattern for this). However, with Post Comments block: Merge Comments Query Loop block #40521, the placeholder will only be used for an empty Post Comments block, so we'll change the warning there to reflect that.
  • Maybe we can re-use the Comment Form block placeholder (Post Comments Form: Add "proper" visual representation in the editor #40368) to render the form here (and de-dupe code), once that's merged.
  • We could consider making the placeholder resemble the Comments Query Loop a bit more -- specifically e.g. by using the post's actual comments when inside the Post Editor.

@ockham
Copy link
Contributor

ockham commented Apr 21, 2022

👋 @ryelle If you can spare some time, could we have your a11y feedback on this PR? It basically adds a placeholder for a post's comments (and comment form) to the editor which cannot really be edited -- really just to have something that somewhat captures what it'll look like on the frontend. We were a bit unsure if this will surface to screenreaders in an undesired way 😅

You need this patch to re-enable the (currently deprecated) Post Comments block:

diff --git a/packages/block-library/src/post-comments/block.json b/packages/block-library/src/post-comments/block.json
index 6c5c4e16b8..8a15e57569 100644
--- a/packages/block-library/src/post-comments/block.json
+++ b/packages/block-library/src/post-comments/block.json
@@ -33,8 +33,7 @@
                                "background": true,
                                "text": true
                        }
-               },
-               "inserter": false
+               }
        },
        "style": [
                "wp-block-post-comments",

Then, insert the Post Comments block in the Post or Site editor to see the placeholder.

@ockham
Copy link
Contributor

ockham commented Apr 21, 2022

(Merging as discussed above; additional feedback to be addressed in follow-up PRs.)

@ockham ockham merged commit 9b1a8fc into trunk Apr 21, 2022
@ockham ockham deleted the fix/add-placeholder-to-post-comments-block branch April 21, 2022 17:10
@github-actions github-actions bot added this to the Gutenberg 13.2 milestone Apr 21, 2022
@ockham ockham added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Apr 21, 2022
@ryelle
Copy link
Contributor

ryelle commented Apr 21, 2022

@ockham thanks for the ping 😄 I did some quick testing - I hope this helps.

When I turned on VoiceOver and looked at the different ways to navigate through the page, the content in the Post Comment block shows up. Like in the heading list, the “One response…” and “Leave a Reply” are there, when other headings in the page aren't (because heading blocks have different roles). I think this might be a larger gutenberg issue though, and I don't know what the expected behavior should be.

When the block is added, the first thing I hear is the warning, and then it’s possible to navigate through the whole comment section. I think this is good, since the user would want to know what’s in there. When navigating by keyboard or VoiceOver + keyboard, it’s possible to focus on the links, and activating a link reloads the page (pretty sure the root issue is this #15799). The comment textarea and button are disabled, as expected.

The textarea has no label, not sure if that’s from the theme or something to fix in the block.

I was able to change the styles with keyboard & VoiceOver, but tweaking the typography settings (like letter spacing) also changed the warning. Not an a11y issue, just unexpected 🙂

Screen Shot 2022-04-21 at 1 57 37 PM

@luisherranz
Copy link
Member Author

luisherranz commented Apr 21, 2022

Thanks a lot for the review, @ryelle!

The textarea has no label, not sure if that's from the theme or something to fix in the block.

That's actually my fault. The label is there, but I removed the textarea id because the linter was complaining. I'll fix it in a new PR. Thanks for the heads up!

EDIT: PR created #40527

VoiceOver + keyboard, it's possible to focus on the links, and activating a link reloads the page (pretty sure the root issue is this #15799)

It seems like it, yes.

tweaking the typography settings (like letter spacing) also changed the warning

Yes, @DAreRodz also mentioned it here #40484 (comment). I haven't found any issue that describes that problem, so I'll open one.

EDIT: Issue created #40536.

heading list, the “One response…” and “Leave a Reply” are there, when other headings in the page aren't (because heading blocks have different roles). I think this might be a larger gutenberg issue though, and I don't know what the expected behavior should be.

Do you know about any other block that contains similar headers, but they don't appear? (to take a look at the code and see if they are doing something different).

@ockham
Copy link
Contributor

ockham commented Apr 22, 2022

Thanks a lot for your a11y feedback, @ryelle -- much appreciated!
Thanks @luisherranz for addressing it!

gziolo pushed a commit that referenced this pull request Apr 25, 2022
@gziolo
Copy link
Member

gziolo commented Apr 25, 2022

Cherry-picked to the wp/6.0 branch for WordPress Beta 3 release.

@gziolo gziolo removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Apr 25, 2022
@luisherranz
Copy link
Member Author

Backport of the exposure of the default_comments_status option: WordPress/wordpress-develop#2623

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Apr 25, 2022
This is a backport that exposes the default_comments_status option in the Editor, under the discussion settings, which then is then used by the Post Comments and Post Comments Form blocks.

Related change in Gutenberg: WordPress/gutenberg#40484.

Props luisherranz.
See #55567.



git-svn-id: https://develop.svn.wordpress.org/trunk@53259 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Apr 25, 2022
This is a backport that exposes the default_comments_status option in the Editor, under the discussion settings, which then is then used by the Post Comments and Post Comments Form blocks.

Related change in Gutenberg: WordPress/gutenberg#40484.

Props luisherranz.
See #55567.


Built from https://develop.svn.wordpress.org/trunk@53259


git-svn-id: http://core.svn.wordpress.org/trunk@52848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this pull request Apr 25, 2022
This is a backport that exposes the default_comments_status option in the Editor, under the discussion settings, which then is then used by the Post Comments and Post Comments Form blocks.

Related change in Gutenberg: WordPress/gutenberg#40484.

Props luisherranz.
See #55567.


Built from https://develop.svn.wordpress.org/trunk@53259


git-svn-id: https://core.svn.wordpress.org/trunk@52848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@georgeh georgeh added the [Type] Enhancement A suggestion for improvement. label May 10, 2022
@femkreations femkreations added the Needs User Documentation Needs new user documentation label Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Comments (legacy) The legacy mode of the Comments block (formerly known as Post Comments) Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.