PanelBody: Add headingLevel prop to configure the title heading level#78752
PanelBody: Add headingLevel prop to configure the title heading level#78752Mayank-Tripathi32 wants to merge 2 commits into
headingLevel prop to configure the title heading level#78752Conversation
1807025 to
3c79c9e
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 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. |
ciampo
left a comment
There was a problem hiding this comment.
Is there a real need for this feature? The original issue doesn't highlight any, and no one else commented since its opening in 2020.
There was a problem hiding this comment.
Let's also test for the string version, eg '3'
A good question to answer before moving forward. I see this component as one made for the sidebar. I think it's better to use and recommend |
In fact, I have released a React-based settings page using the Panel component. https://wordpress.org/plugins/custom-html-block-extension/
For my use case, this plugin needed collapsible sections. At the time, the In my case, keeping the panel heading as an |
|
The weird thing I'm noticing is that the I'm not necessarily against adding heading level props to this component family, since the component is not going away. But given that any third-party need for this customization is not for the block inspector, we could maybe just say that |
True but is it really that much work to add and maintain this for panel family? Other components have it already. I think it makes sense to have similar option in panel aswell. |
|
If we want to recommend the use of the |
|
@Mayank-Tripathi32, less code to maintain is always better; there's no real cost for this singular case, but it all adds up eventually. I also don't see a real benefit in recommending |
|
Understood, Lets just add the note in that case. I can open up a PR for it later today. |
|
Closing in favour of #78863 |

What?
Closes #26867
Adds a
headingLevelprop toPanelBodyso the title can render ash1–h6instead of always being anh2. Defaults to2, so existing usage is unchanged.Why?
PanelBodyhardcoded its title in an<h2>. When used outside the core sidebar context (e.g. plugins reflecting their own document outline), that fixed level breaks the heading hierarchy, forcing authors to fork the component. This matches theheadingLevelprop already offered byToolsPanel,ColorPalette, andGradientPicker.How?
headingLevel?: HeadingSizetoPanelBodyProps/PanelBodyTitleProps(reusing the sharedHeadingSizetype).h${ headingLevel }instead of a literal<h2>. Styling is unchanged —.components-panel__body-titleis class-based withfont-size: inherit, so only the tag/semantics change.Testing Instructions
PanelBody. By default the title renders as an<h2>.headingLevel={ 3 }and confirm the title renders as an<h3>(inspect the DOM) with unchanged visual appearance.npm run test:unit packages/components/src/panel/test/body.tsx— includes new cases for the default level (2) and a custom level (3).Testing Instructions for Keyboard
No interaction changes — the toggle button inside the heading behaves exactly as before.
Use of AI?