Skip to content

Accordion: fix padding/border showing on closed panels - #80777

Open
vedant-ere wants to merge 2 commits into
WordPress:trunkfrom
vedant-ere:fix/accordion-panel-hidden-padding
Open

vedant-ere wants to merge 2 commits into
WordPress:trunkfrom
vedant-ere:fix/accordion-panel-hidden-padding

Conversation

@vedant-ere

@vedant-ere vedant-ere commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

What?

Fixes closed Accordion panels showing extra space when the panel has padding or a border set (for example through theme.json spacing).

Why?

Closes #80776

When an accordion item is closed, the panel gets hidden="until-found". Browsers turn this into content-visibility: hidden, which hides and collapses the panel's content, but not the panel's own padding or border. So if the panel has padding or a border applied, that space stays visible even while the panel is closed, pushing the accordion items apart.

The panel's stylesheet already reset margin-block-start for this exact reason, but never accounted for padding or border causing the same problem.

How?

Extended the existing [hidden] rule in packages/block-library/src/accordion-panel/style.scss to also zero out padding and border-width when the panel is hidden, so a closed panel always collapses fully no matter what spacing or border settings are applied to it.

Testing Instructions

  1. Insert an Accordion block with a couple of items, panels closed by default.
  2. Add padding (and/or a border) to the Accordion Panel block through the style settings.
  3. Save and view the page on the frontend.
  4. Before this fix: closed panels still show a gap matching the padding size.
  5. After this fix: closed panels take up no space, and the gap only appears once a panel is opened.

Closed accordion panels get hidden="until-found", which browsers
render as content-visibility: hidden. That only collapses the panel's
content, not its own padding or border, so panels with padding or a
border (e.g. via theme.json) still show a visible gap while closed.

Zero out padding and border-width on [hidden] panels alongside the
existing margin reset, so closed panels always collapse fully.
@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Block library.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: vedant-ere <vedantere@git.wordpress.org>
Co-authored-by: hanneslsm <hanneslsm@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added [Package] Block library /packages/block-library First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository labels Jul 28, 2026
@github-actions

Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @vedant-ere! 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accordion Panel: Padding is also shown in accordion with closed panels

1 participant