Skip to content

Accordion: Add BlockGap support to content & panel#71461

Merged
t-hamano merged 10 commits intoWordPress:trunkfrom
yashjawale:fix/accordion-block-spacing
Sep 4, 2025
Merged

Accordion: Add BlockGap support to content & panel#71461
t-hamano merged 10 commits intoWordPress:trunkfrom
yashjawale:fix/accordion-block-spacing

Conversation

@yashjawale
Copy link
Contributor

@yashjawale yashjawale commented Sep 2, 2025

What?

Closes #71433

This PR fixes issue of block spacing setting not working for accordion content

Why?

Currently, changing the value of Block spacing from Inspector doesn't have any effect. Ideally it should add block spacing styles to accordion content

How?

This PR adds layout field to block.json for Accordion content & panel so that block spacing setting works
For accordion-content block, addtional handling via use of useSpacingProps was needed for blockGap changes to reflect
Styling specificity is modified so that the margin applied by blockSpacing settings of AccordionContent block don't affect the spacing when accordions are closed (this one is handled by spacing set by main parent Accordion block) & instead is only utilized for separation between Accordion header & panel.

Testing Instructions

  1. Enable experimental blocks
  2. Create a new post or page
  3. Insert Accordion block
  4. Click the Accordion Content or Accordion Panel block.
  5. Change the Block Spacing setting.
  6. Observe the changes

Screenshots or screencast

Before

Screen.Recording.2025-09-03.at.12.48.38.PM.mov

After

Screen.Recording.2025-09-03.at.1.32.44.PM.mov

@t-hamano
Copy link
Contributor

t-hamano commented Sep 3, 2025

Thanks for working on this PR.

In #71454, the extra wrapper div has been removed from the Accordion Panel, so can you rebase this PR on top of trunk and confirm the blockGap support works?

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Accordion Affects the Accordion Block labels Sep 3, 2025
@yashjawale
Copy link
Contributor Author

@t-hamano thanks for notifying about the change 🙌

I've merged the updates & the blockGap support works as expected

Screen.Recording.2025-09-03.at.1.40.10.PM.mov

@yashjawale yashjawale marked this pull request as ready for review September 3, 2025 08:26
@github-actions
Copy link

github-actions bot commented Sep 3, 2025

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: yashjawale <yashjawale@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

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

Comment on lines 76 to 79
style: {
...blockProps.style,
...spacingProps.style,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is only necessary if we want to skip serialization of block support or apply styles to elements within a block.

We might take this opportunity to simplify it to:

const blockProps = useBlockProps( {
	className: clsx( {
		'is-open': openByDefault || isSelected,
	} ),
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {
	template: [
		[ 'core/accordion-header', {} ],
		[
			'core/accordion-panel',
			{
				openByDefault,
			},
		],
	],
	templateLock: 'all',
	directInsert: true,
	templateInsertUpdatesSelection: true,
} );

}

.accordion-content__heading {
:where(.accordion-content__heading) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this style necessary in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already present before the change...
I'll check if removing that style causes any visible effect
If that doesn't change anything then the workarounds below won't be needed


.is-layout-flow > .wp-block-accordion-panel,
.wp-block-accordion-panel {
:where(.is-layout-flow > .wp-block-accordion-panel, .wp-block-accordion-panel) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For accordion content block, this rule was preventing the margin from being applied for blockGap to work
This change lowers the specificity so that margin applied by blockGap could work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just removing margin: 0 here?

.wp-block-accordion-panel is just a div element, so I'm not sure why margin:0 is necessary in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll try finding why was that added
ig removing margin: 0 shouldn't cause any problems & then the workarounds won't be needed too

Comment on lines 53 to 57
// Override block spacing for closed accordion panels specifically.
// Higher specificity to ensure it overrides block spacing margins.
.wp-block-accordion-content:not(.is-open) > * + .wp-block-accordion-panel {
margin-block-start: 0 !important;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I've tested, I don't understand what this style is trying to fix - what specific problem does it cause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we set blockGap on Accordion content, the margin still remains when the accordion is collapsed
This rule overrides it to zero so that additional margin isn't applied for collapsed accordions (user would use block gap of parent accordion block to set that spacing), so the content block's gap would just affect the spacing between header & panel

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, then, how about a selector like this? I'm not sure why aria-hidden is used in the editor and inert on the front end, but maybe we can unify this in a follow-up.

.wp-block-accordion-panel[inert],
.wp-block-accordion-panel[aria-hidden="true"] {
}

@yashjawale
Copy link
Contributor Author

Updated ✅
Removing margin: 0 did the trick, Thanks!
The rule was added in #64119 itself but couldn't find any clues as to why it was added
Removed the other workarounds revolving around it too

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Everything works as expected 👍

@t-hamano t-hamano merged commit 28bf4c6 into WordPress:trunk Sep 4, 2025
77 of 78 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.7 milestone Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Accordion Affects the Accordion Block [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accordion Content, Accordion Panel: blockGap support doesn't work

2 participants