-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Feature: Adding support for more granular controls over the ToC block #69063
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
Feature: Adding support for more granular controls over the ToC block #69063
Conversation
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: @jodamo5. 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. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @gmovr! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
I tested it using Playgound, and it works as expected. Kapture.2025-02-06.at.15.50.21.mp4 |
The last design guidance on #51605 is from 2023, so I think we need a fresh perspective there. The toggle + dropdown seems a bit unnecessary to me. Either way, I don't think we need two attributes for this. |
] } | ||
onChange={ ( value ) => | ||
setAttributes( { | ||
maxLevel: parseInt( value, 10 ), |
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.
FYI passing radix 10 isn't needed and hasn't been for like 10 years. parseInt( value )
is enough
Where is this coming from? I don't see a feature request for it. IMHO this is better discussed in a new issue first before trying to add this in via this PR. There might be alternative approaches for this, e.g. with a new attribute on the heading block, or with a different class name or so. Hence best to split this up. |
Thanks for the feedback. This is coming from my own use wihin the team that update our blog. Often we do not want certain headings in the ToC, and to accomplish this now, we need to convert it to a static list. I was considering setting it on the heading block, but it felt a bit inverse in this case, as most pages will have headings while fewer will have the ToC block. So IMO the ToC block should contain ToC logic. I'm open to either approach, though, or moving it to an issue and a subsequent PR. :) |
That makes sense! I will change the filtering logic. |
To clarify, my suggestion was not necessarily to do the inverse, but for example to introduce a proper toggle on the heading block that the TOC block could then use. I would also take a look at how Google Docs does this for example. You can remove a heading from the TOC simply by clicking on an "X" next to it. That's why I think this needs its own issue & discussion first. |
@swissspidy -- I've implemented your suggestions for the heading-level filtering. Could you take another look, please? Thanks |
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 it looks good, but I'd like others to chime in who are more active in this component.
@ZebulanStanphill could you have a look at this PR? |
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.
Thank you, @gmovr!
The implementation looks good; I just have a couple of minor suggestions.
I think the maxLevel
solution makes more sense here, compared to the allowed levels
, where the user can specify exactly which levels to display.
…, such as heading level, and the option for excluding certain headings via a css class
…cluding all heading levels. Rebuild docs.
…l value in the filtering logic
a27020a
to
89dc817
Compare
@Mamaduka --- Thanks for the suggestion. That's a better way of doing it, and I've done the changes now. Could you take another look? I also rebased it on top of the latest trunk, just in case, as this branch is getting a bit old. |
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.
Thank you, @gmovr!
We need to do a bit cleanup after switching to undefined
, but besides that everything looks great ✅
P.S. Running npm run fixtures:regenerate
should fix failing JS unit tests.
Thanks! There's one more issue now, if you change the heading level, the save button does not become enabled, I wonder if it is due to a missing default value, or do we need to persist this data? Doing an edit in the editor will sort it, and the change is carried over, but changing this setting just by itself isn't seen as a "saveable" change by the editor. 🤔 |
I believe that's the same issue as #67583 and urelated to this PR. Unfortunately, problems like that are the reason the block is still experimental. |
Thanks! That makes see :) |
…WordPress#69063) Unlinked contributors: jodamo5. Co-authored-by: gmovr <etobiesen@git.wordpress.org> Co-authored-by: swissspidy <swissspidy@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: mrfoxtalbot <mrfoxtalbot@git.wordpress.org> Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org> Co-authored-by: JosVelasco <josvelasco@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org>
What?
Closes #51605
Additionally, we allow the user to explicitly exclude a given heading by giving the heading a class ofRemoved as out of scope.toc-exclude
. This will exclude it from the ToC, even if the given settings for heading level would qualify it.Why?
On several sites, the ToC block is too rigid, and we're forced to convert it to a static list. This is subpar, as it loses the logic, and a changed heading will lead to a broken link reference.
How?
The exclude feature is necessary, as some users may want to include headings for SEO purposes, that are not necessarily wanted in the ToC.Testing Instructions
toc-exclude
class on a heading.Just like a TV cooking show, I've prepared some code you can paste into the editor to test this:
Testing Instructions for Keyboard
We use standard components only adding a standard select box.
Screenshots or screencast