-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Block Supports: Add Line Indent support using enum setting #74889
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
|
Size Change: +1.44 kB (+0.05%) Total Size: 3 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 06349da. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/21393931849
|
|
Thanks for working on this PR!
In fact, text indentation rules aren't determined by language direction. Japanese and Chinese are LTR languages, but they indent all paragraphs. See #74200. On the other hand, Arabic, an RTL language, doesn't indent the first paragraph, as far as I've researched. Therefore, I think it's difficult to change the default value depending on the language direction. If the default value can be overridden via theme.json, I think the default value of "subsequent" is fine. What do you think? |
|
Thanks for the clarification @t-hamano 👍
Works for me. Having one less filter, less code overall, and less "automagic" tweaks of settings, just sounds better to me. I'll update this shortly. |
1a80d95 to
06349da
Compare
andrewserong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the follow-up, this is testing very nicely for me, and I think the enum approach works pretty well 👍
The only real feedback I had is about the design of the controls and help text on the controls.
For the individual block level, I wonder if the help text is necessary? Could we go without it, if line indent as a label is clear enough?
In global styles, things get interesting as the panel can look pretty cluttered with everything in there:
I'm not quite sure what the ideal solution would be here, but to me the toggle could be a little bit confusing because when I see a toggle I think "on/off", whereas this is toggling between two states where in each state the text indent is still "on":
| off | on |
|---|---|
![]() |
![]() |
This leads me to wonder:
- How necessary is it for there to be a UI control to toggle it? I.e. is it up to the site owner
- If it is necessary, how might we simplify it? Are any of the alternatives neater (e.g. toggle control / select control, etc?)
Apologies, I'm no designer and not many ideas come to mind to how to simplify 🤔
Other than that, the feature's looking really good to me!
| "selectors": { | ||
| "root": "p", | ||
| "typography": { | ||
| "textIndent": ".wp-block-paragraph + .wp-block-paragraph" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for now, but if we ever want to canonically support multiple different kinds of blocks with textIdent and across each of the options (subsequent and all), we could potentially expand the API here to make blocks able to declare the selectors themselves. I.e. something like:
"selectors": {
"typography": {
"textIndent": {
"subsequent": ".wp-block-paragraph + .wp-block-paragraph",
"all": ".wp-block-paragraph"
}
}
}
IMO this would be overkill for now, as it's not that much code to have a function handle the transformation, and I don't believe there's an immediate plan to support other blocks than the paragraph block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider this approach but also settled on the same conclusion that it was overkill for now.
I don't believe there's an immediate plan to support other blocks than the paragraph block?
Not that I'm aware of.
|
Appreciate the testing and thoughtful feedback @andrewserong 👍 I've removed the help text from the block instance control.
I think I get what you're saying but it may just be a matter of perspective. The toggle control does represent and on/off state. Here though, that would be for the "indent all paragraphs" mode not the block support. Other alternatives like, a select control or 2 radio buttons, looked more weird. None address the "clutter" introduced here though either.
Apparently necessary, this was a direct requirement due to certain languages needing to apply line indents differently while also wanting to provide that control site owners in general.
I don't have many ideas either except maybe reordering things so the help text was below the toggle but to me that looked more off. Taking the relocation further the indent field could be moved to the very bottom, I don't have much in the way of a strong opinion here. There's a slight mitigating factor here that might allow us to proceed and refine later. This block support will be added for only the paragraph block for now and this control will only appear under Styles > Blocks > Paragraph > Typography once the user toggles it on specifically. So it is pretty niche at the moment. |
540f221 to
4e44428
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @ericmacknight. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Agreed, thanks for expanding on your thinking here! From my perspective the critical piece to settle on is the shape of the API in |
Sounds good @andrewserong 👍 I'll sort out the tests and get this to a place to get further reviews and merge. |
4e44428 to
b44b451
Compare
t-hamano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Apologies, I'm no designer and not many ideas come to mind to how to simplify 🤔
I don't have many ideas either except maybe reordering things so the help text was below the toggle but to me that looked more off. Taking the relocation further the indent field could be moved to the very bottom, I don't have much in the way of a strong opinion here.
Does it make sense to add a help text to the ToggleControl?
This approach is similar to the fitText support:
packages/block-editor/src/components/text-indent-control/index.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
b44b451 to
0aa6b27
Compare
|
Appreciate the reviews @t-hamano and @andrewserong 👍 I think I've addressed the majority of the feedback. Including moving the help text to the ToggleControl. What do you think of pushing this forward so the feature lands before the beta and we can tweak further based off feedback? |
andrewserong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've addressed the majority of the feedback. Including moving the help text to the ToggleControl.
This is looking good: I like that the help text is on the ToggleControl and that things are more streamlined at the block instance level 👍. Testing well:
2026-02-02.12.23.34.mp4
What do you think of pushing this forward so the feature lands before the beta and we can tweak further based off feedback?
Yes, I think this is in a really good place to land now. The features are all there and working nicely, I think most of the iteration through the beta period would be on UI or minor tweaks rather than anything major, so +1 let's get it in.
Thanks for all the back and forth here! 🚀
Unlinked contributors: ericmacknight. Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: mtias <matveb@git.wordpress.org> Co-authored-by: skorasaurus <skorasaurus@git.wordpress.org> Co-authored-by: justintadlock <greenshady@git.wordpress.org> Co-authored-by: kjellr <kjellr@git.wordpress.org>
|
Just added the label |


What?
Closes #37462
Follow up to #73114
Alternative to #74863
Adds CSS
text-indentsupport for paragraph blocks with traditional typography conventions - subsequent paragraphs get first-line indented in LTR languages, with an option to indent all paragraphs (default for RTL languages).Why?
Text indentation is a fundamental typography feature that's been requested since 2021. Traditional print typography conventions dictate that only subsequent paragraphs (not the first) should have their first line indented in LTR languages, while RTL languages typically indent all paragraphs. This feature enables proper typographic styling that matches publishing standards.
How?
The previous attempt (#73114) was reverted due to unresolved edge cases where the use of a simple
pelement in the global styles selector would cause indentation to bleed into other undesired blocks.Since the original PR, paragraph blocks now get a
.wp-block-paragraphclass added to them enabling the Line Indent support to target this and restrict indentation to only paragraphs.Implementation approach:
This implementation uses a single
textIndentstyle property with an enum-based setting that controls which CSS selector is used:'subsequent'(default for LTR): Uses.wp-block-paragraph + .wp-block-paragraphselector (subsequent paragraphs only)'all'(default for RTL): Uses.wp-block-paragraphselector (all paragraphs)The selector is dynamically adjusted during CSS generation based on the setting value, using a post-processing pattern similar to how separator block styles are handled. This avoids the complexity of maintaining two separate style properties (see #74863) while still providing the flexibility to target different selectors.
Key features:
textIndentproperty with enum setting for selector controlTechnical implementation:
selectors.typography.textIndent)update_paragraph_text_indent_selector()function post-processes feature declarationsupdateParagraphTextIndentSelector()mirrors the PHP logic for editor preview'all'for right-to-left languagesTesting Instructions
Basic Usage
Global Styles
RTL Testing
Example Theme.json
Add the following to your theme's theme.json to enable text indent with the "all paragraphs" mode:
{ "settings": { "typography": { "textIndent": "all" } }, "styles": { "blocks": { "core/paragraph": { "typography": { "textIndent": "1.5em" } } } } }For subsequent paragraphs only (the default), use
"textIndent": "subsequent"or simply"textIndent": truein settings.