Add toggle group support with default toggle functionality#37
Merged
jeremyfelt merged 4 commits intotrunkfrom Mar 10, 2026
Merged
Add toggle group support with default toggle functionality#37jeremyfelt merged 4 commits intotrunkfrom
jeremyfelt merged 4 commits intotrunkfrom
Conversation
When toggle blocks are placed inside a container with the `toggle-block-group` class, they behave like tabs: activating one toggle automatically closes all others in the group. Adds a "Default toggle" option that marks which toggle should be active by default when no other toggle in the group is open. https://claude.ai/code/session_019mVP8YLjaU9V5LEzsujoCL
|
Changed files were detected after build. Please run project build workflows and check You may need to update your local NPM configuration if different than below:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for toggle groups, allowing multiple toggle blocks to be organized together where only one can be active at a time. It also introduces a "default toggle" feature that automatically activates a specified toggle when no toggle in the group is currently active.
Key Changes
Refactored toggle logic: Split the monolithic
handleClickfunction into smaller, reusable functions:toggleOn(): Handles showing a controlled elementtoggleOff(): Handles hiding a controlled elementgetToggleGroup(): Finds the parent toggle groupgetGroupToggles(): Gets all toggles within a groupgetDefaultToggle(): Finds the default toggle in a groupToggle group behavior: When a toggle is clicked within a group:
Default toggle initialization: Added initialization logic that activates the default toggle in each group on page load if no toggle is already active
UI enhancements: Added a "Default toggle" toggle control in the block editor inspector panel
Block attributes: Added
defaultToggleboolean attribute to track which toggle should be the default in a groupDeprecated version: Added a deprecated block version to maintain backward compatibility with existing toggle blocks
Implementation Details
handleClickfunction now usesclosest()to find the toggle button, making it more robust for nested elements.toggle-block-groupCSS classdata-default-toggle="true"attributehttps://claude.ai/code/session_019mVP8YLjaU9V5LEzsujoCL