-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add CSS class to paragraph block #47282
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
Conversation
|
I'll be working on fixing tests and all. |
# Conflicts: # lib/compat/wordpress-6.2/block-patterns/centered-footer-with-social-links.php # lib/compat/wordpress-6.2/block-patterns/centered-footer.php # lib/compat/wordpress-6.2/block-patterns/footer-with-large-font-size.php # lib/compat/wordpress-6.2/block-patterns/simple-header-with-image.php
…k and affect test results.
# Conflicts: # packages/block-editor/src/hooks/test/__snapshots__/align.native.js.snap # packages/block-library/src/cover/test/__snapshots__/edit.native.js.snap # packages/block-library/src/embed/test/__snapshots__/index.native.js.snap # packages/e2e-tests/specs/editor/blocks/__snapshots__/heading.test.js.snap # packages/e2e-tests/specs/editor/blocks/pullquote.test.js # packages/e2e-tests/specs/editor/plugins/__snapshots__/container-blocks.test.js.snap # packages/e2e-tests/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap # packages/e2e-tests/specs/editor/plugins/__snapshots__/inner-blocks-render-appender.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/block-deletion.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/block-grouping.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/block-hierarchy-navigation.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/embedding.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/keep-styles-on-block-transforms.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/list-view.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap # packages/e2e-tests/specs/editor/various/__snapshots__/rich-text.test.js.snap # packages/e2e-tests/specs/editor/various/block-grouping.test.js # packages/e2e-tests/specs/editor/various/format-library/__snapshots__/text-color.test.js.snap # packages/e2e-tests/specs/editor/various/multi-block-selection.test.js # packages/e2e-tests/specs/widgets/editing-widgets.test.js # packages/format-library/src/text-color/test/__snapshots__/index.native.js.snap # packages/react-native-editor/__device-tests__/helpers/test-data.js # packages/react-native-editor/src/initial-html.js # packages/rich-text/src/test/__snapshots__/index.native.js.snap # test/e2e/specs/editor/blocks/__snapshots__/List-can-be-exited-to-selected-paragraph-1-chromium.txt # test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-1-chromium.txt # test/e2e/specs/editor/various/font-size-picker.spec.js # test/integration/__snapshots__/blocks-raw-handling.test.js.snap
# Conflicts: # packages/e2e-tests/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap # packages/e2e-tests/specs/editor/various/multi-block-selection.test.js
|
I'm not sure we should do this. The original issue describes problems with site tagline and site title, two blocks that are good candidates to be a paragraph block + bindings in the future instead of separate custom blocks, so they would probably inherit the classes anyways. |
|
I think we must to consider other than core blocks, anything that uses |
I would like to recommend this approach, but implementing it in this PR would require reverting too many files, so I have submitted a new #71207. |
|
What is the use case for setting styles on the paragraph block? |
For example, a user may want to change the typography styles on the Paragraph block via the global styles. The problem is that this style will affect The purpose of this PR is similar to #42122. |
Why would a user want to do this? What would it achieve? |
I don't think there's any particular reason. I think users simply want to change the style of the paragraph block, just like with any other block. |
Without a use case in mind it's hard to be certain that the current behaviour is not the right one :) |
|
Users want to apply styles to Paragraph blocks only, without affecting other |
I think it's conceivable that someone out there might want to:
Why not? Edit: I realize this is already possible, but I forgot to mention the assumption that it'd be done to the exclusion of paragraph elements that live in cover blocks for example. In that case, you'd want the cover block global style to have precedence. All that comes to mind is a news site - it's text-based, and article paragraphs have a syntactical relevance that might need to be style to the exclusivity of all others. I'm reaching 😄 Might be an edge case; the original issue outlines another. Can folks think of better examples? |
Exactly. And to have different styling for P elements inside other blocks without added complexity. |
Thanks for the example @ramonjd. In this case I would expect that styling the Post Content block would be more effective, since paragraph blocks are more general purpose. |
|
Please note that there is also a classic theme that has a theme.json. The post content block does not exist in the classic theme. |
|
I think we are missing the reason why there is a reluctancy to add this. I don't see the motivation voiced here? A motivation such as "I think it is a bad idea to add a class to the paragraph because it will increase the size of the markup exactly because the paragraph is the most used block". One person made the argument that the current way the paragraph is styled may be wrong. |
I don't think the fact that global styles and theme.json support the paragraph block is a problem in itself, but I think the important thing is whether we should use an element or class name selector. Currently, the Paragraph block is the only core block that defines an element as a selector instead of a wrapper classname, which I find strange. P.S. I did a bit of history research and discovered that the wrapper classname for the Paragraph block (formerly known as the Text block) was intentionally disabled from the very beginning when the mechanism was introduced (over 8 years ago!). I'm not sure why the wrapper classname was disabled, but maybe there was no global styles or theme.json back then, so there was no need for a classname on paragraph elements. |
|
For a more limited approach, I updated #71207. That PR dynamically adds a CSS class to the Paragraph block, but keeps the CSS selector as it was: |
|
Thanks for the update, @t-hamano! I see #71207 takes the render-only approach vs. also including the classname in the editor context (className disabled for block). Makes sense as a more limited scope, we've been working on this angle for a while. Since #71207 has been merged, I'll go ahead and close this PR. |
|
As a follow-up to #71207, we could revisit the following if necessary:
|
I'm not sure on this one. Like with the current approach to adding the class name in a backward compatible manner, would this provide any benefits?
I'm generally wary when it comes to increasing any CSS specificity. More detailed discussion might be better on the linked issue.
If we are looking for generic site wide text styles I think we sort of already have that covered via the It's also possible that |
There is no particular benefit 😅 I was just wondering if we should inject the class name into the Paragraph block as well as the Heading block:
Regarding this, #47282 (comment) by @justintadlock may be helpful.
|
This is just my two cents but I think we could start out by not updating the root selector for the paragraph block, leaving it as |
Addition by @t-hamano
To resume this PR, I did the following:
This PR has a lot of diffs, mostly related to testing and documentation updates.
The actual files to check are:
packages/block-library/src/paragraph/block.json: The paragraph block will have the class namewp-block-paragraphadded to it, and the CSS selectors generated by the global styles will also use this class.packages/block-library/src/paragraph/index.php: Add a class name to the Paragraph block that is already saved in the database via the render callback function.phpunit/block-supports/layout-test.phpphpunit/block-supports/typography-test.phpphpunit/class-wp-theme-json-test.phpphpunit/blocks/render-block-media-text-test.phpphpunit/blocks/render-block-paragraph-test.phpOriginal description by @juanfra
What?
Adding the
wp-block-paragraphto the paragraph block elements.Fixes #46863
Why?
It was reported in #46863 that the style changes for the paragraph block were affecting all the paragraphs, and this was affecting other pieces of the site such as the site tagline (and others).
How?
Adding the
wp-block-paragraphclass to the paragraph block for new content, and parsing the block output to add it for previously generated content.Testing Instructions
For new content
wp-block-paragraphclass.For previously generated content
wp-block-paragraphclass was added to the previously generated content.For the problem reported in #46863
<p>that doesn't have thewp-block-paragraphclass)Screenshots or screencast
Screen.Recording.2023-02-03.at.17.18.43.mov