Skip to content

Add icon state classes to Accordion block#74257

Draft
deepakpra wants to merge 1 commit into
WordPress:trunkfrom
deepakpra:fix/accordion-icon-state-classes
Draft

Add icon state classes to Accordion block#74257
deepakpra wants to merge 1 commit into
WordPress:trunkfrom
deepakpra:fix/accordion-icon-state-classes

Conversation

@deepakpra

Copy link
Copy Markdown

What?

Closes #74254

Adds icon state CSS classes to the Accordion block wrapper in both the editor and saved markup.

When the icon is enabled, the block now outputs:

  • has-icon
  • has-icon-left or has-icon-right, based on the selected icon position

Why?

The Accordion block already exposes icon visibility and position as attributes, but this state was not reflected in the rendered markup.

Exposing this state via CSS classes provides a consistent, attribute-driven styling hook and aligns the Accordion block with established Gutenberg patterns.

How?

Computes icon-related CSS classes from existing attributes (showIcon, iconPosition)

Applies the computed classes to:

edit.js for editor markup

save.js for frontend and serialized markup

Uses clsx with a descriptive variable name to keep the logic clear and maintainable

Does not introduce new attributes or change the block structure

Testing Instructions

  1. Insert an Accordion block
  2. Toggle Show icon on
  3. Verify has-icon is added
  4. Set Icon position to Right
  5. Verify has-icon-right is added
  6. Set Icon position to Left
  7. Verify has-icon-left is added
  8. Toggle Show icon off
  9. Verify no icon-related classes are present
  10. Confirm the same behavior in both the editor and frontend markup
image

@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: deepakpra <deepakprajapati@git.wordpress.org>
Co-authored-by: mrleemon <leemon@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 Dec 29, 2025
@github-actions

Copy link
Copy Markdown

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

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Accordion Affects the Accordion Block labels Dec 30, 2025
@deepakpra deepakpra marked this pull request as draft December 30, 2025 07:25
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 First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accordion block: Add dynamic CSS class based on icon visibility/position

2 participants