Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fe0aaee
Add initial accordion implementation.
jffng Jul 30, 2024
ebfc5f5
Refactor blocks for core loading.
jffng Jul 30, 2024
c58232f
Simplify state getter by storing id in the context.
jffng Aug 1, 2024
4698eee
Clean up tag processing and try to initialize state on the server.
jffng Aug 2, 2024
3c2c54b
Don't enqueue the frontend files if there's no content
luisherranz Aug 6, 2024
d4101b4
Stringify the autoclose value
luisherranz Aug 6, 2024
872ecf1
Refactor to populate `context.isOpen` on the server
luisherranz Aug 6, 2024
5f9e24a
Add comments to the server side rendering functions.
jffng Aug 6, 2024
b790e90
Improve the block editing UX
jffng Aug 6, 2024
7a05993
Reword the auto-close toggle help text.
jffng Aug 12, 2024
cea68d0
Add padding to the content and trigger by default.
jffng Aug 12, 2024
96c37c9
Fix aria-labelledby and aria-controls references.
jffng Aug 14, 2024
151655b
Allow HeadingLevelOptions to be extended.
jffng Aug 14, 2024
37315e4
Only allow bold, italic, image, and strikethrough for the Trigger.
jffng Aug 16, 2024
7f17891
Disable keyboard navigation for focusable elements when aria-hidden i…
jffng Aug 16, 2024
6c91e72
Fix __next40pxDefaultSize linting error.
jffng Aug 16, 2024
72fdd46
Refactor how state and context are initialized to avoid the need for …
jffng Aug 16, 2024
5967cf1
Use strings for openByDefault so boolean is in the generated JSON.
jffng Sep 3, 2024
db03ba8
Use inert instead of aria-hidden.
jffng Sep 3, 2024
93deeee
Rename Trigger and Content to Header and Panel.
jffng Sep 16, 2024
84112e3
Rename interactivity to script modules.
jffng Sep 16, 2024
542ac20
Remove unused watch directive for setting the tabIndex.
jffng Sep 16, 2024
2d07fba
Merge branch 'trunk' into try/accordion-block
mikachan Aug 4, 2025
5ccd5e3
Move icon controls to top level
mikachan Aug 5, 2025
89f3ffd
Fix linting
mikachan Aug 5, 2025
2916ba6
Remove old GB experiments
mikachan Aug 5, 2025
6fa545e
Remove icon selection
mikachan Aug 8, 2025
df7ee79
Select first Accordion Header by default
mikachan Aug 8, 2025
1715381
Fix icon logic in save.js
mikachan Aug 8, 2025
8d3aa4a
Remove layout controls from header and panel
mikachan Aug 8, 2025
0f2ee27
Fix RTL icon position
mikachan Aug 8, 2025
445f1d1
Remove layout from group and item
mikachan Aug 8, 2025
d4bb0e4
Add layout to accordion group
mikachan Aug 11, 2025
f713c57
Rename Accordion Group to Accordions
mikachan Aug 12, 2025
fb546f7
Use single useSelect
mikachan Aug 13, 2025
0be4b65
Move accordion icons to icon library
mikachan Aug 13, 2025
237af26
Remove color and padding from heading styles
mikachan Aug 13, 2025
43dc276
Make heading CSS less specific
mikachan Aug 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move icon controls to top level
  • Loading branch information
mikachan committed Aug 5, 2025
commit 5ccd5e3a9aa355385730e2e9cee6430ef9a2b66f
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A group of headers and associated expandable content. ([Source](https://github.c
- **Category:** design
- **Allowed Blocks:** core/accordion-item
- **Supports:** align (full, wide), background (backgroundImage, backgroundSize), color (background, gradient, text), interactivity, layout, shadow, spacing (blockGap, margin, padding), ~~html~~
- **Attributes:** allowedBlocks, autoclose, iconPosition
- **Attributes:** allowedBlocks, autoclose, icon, iconPosition

## Accordion Header

Expand Down
16 changes: 16 additions & 0 deletions packages/block-library/src/accordion-group/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@
"type": "string",
"default": "right"
},
"icon": {
"type": [ "string", "boolean" ],
"enum": [
"plus",
"chevron",
"chevronRight",
"caret",
"circlePlus",
false
],
"default": "plus"
},
"autoclose": {
"type": "boolean",
"default": false
Expand All @@ -55,6 +67,10 @@
"type": "array"
}
},
"providesContext": {
"core/accordion-icon": "icon",
"core/accordion-icon-position": "iconPosition"
},
"allowedBlocks": [ "core/accordion-item" ],
"textdomain": "default",
"style": "wp-block-accordion-group"
Expand Down
76 changes: 74 additions & 2 deletions packages/block-library/src/accordion-group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,33 @@ import {
InspectorControls,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { PanelBody, ToggleControl } from '@wordpress/components';
import {
PanelBody,
ToggleControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';
/**
* Internal dependencies
*/
import {
caret,
chevron,
chevronRight,
circlePlus,
plus,
} from '../accordion-item/icons';

const ACCORDION_BLOCK_NAME = 'core/accordion-item';
const ACCORDION_BLOCK = {
name: ACCORDION_BLOCK_NAME,
};

export default function Edit( { attributes: { autoclose }, setAttributes } ) {
export default function Edit( {
attributes: { autoclose, icon, iconPosition },
setAttributes,
} ) {
const blockProps = useBlockProps();

const innerBlocksProps = useInnerBlocksProps( blockProps, {
Expand All @@ -41,6 +60,59 @@ export default function Edit( { attributes: { autoclose }, setAttributes } ) {
'Automatically close accordions when a new one is opened.'
) }
/>
<ToggleGroupControl
__nextHasNoMarginBottom
__next40pxDefaultSize
isBlock
label={ __( 'Icon' ) }
value={ icon }
onChange={ ( value ) =>
setAttributes( { icon: value } )
}
>
<ToggleGroupControlOptionIcon
label="Plus"
icon={ plus }
value="plus"
/>
<ToggleGroupControlOptionIcon
label="Chevron"
icon={ chevron }
value="chevron"
/>
<ToggleGroupControlOptionIcon
label="Circle Plus"
icon={ circlePlus }
value="circlePlus"
/>
<ToggleGroupControlOptionIcon
label="Caret"
icon={ caret }
value="caret"
/>
<ToggleGroupControlOptionIcon
label="Chevron Right"
icon={ chevronRight }
value="chevronRight"
/>
<ToggleGroupControlOption
label="None"
value={ false }
/>
</ToggleGroupControl>
<ToggleGroupControl
__nextHasNoMarginBottom
__next40pxDefaultSize
isBlock
label={ __( 'Icon Position' ) }
value={ iconPosition }
onChange={ ( value ) => {
setAttributes( { iconPosition: value } );
} }
>
<ToggleGroupControlOption label="Left" value="left" />
<ToggleGroupControlOption label="Right" value="right" />
</ToggleGroupControl>
</PanelBody>
</InspectorControls>
<div { ...innerBlocksProps } />
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/accordion-group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@

wp_enqueue_script_module( '@wordpress/block-library/accordion-group' );

$p = new WP_HTML_Tag_Processor( $content );

Check warning on line 32 in packages/block-library/src/accordion-group/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 13 spaces but found 9 spaces
$autoclose = $attributes['autoclose'] ? 'true' : 'false';

Check warning on line 33 in packages/block-library/src/accordion-group/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
$icon = $attributes['icon'] ?? 'plus';

Check warning on line 34 in packages/block-library/src/accordion-group/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space
$icon_position = $attributes['iconPosition'] ?? 'right';

if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion-group' ) ) ) {
$p->set_attribute( 'data-wp-interactive', 'core/accordion' );
$p->set_attribute( 'data-wp-context', '{ "autoclose": ' . $autoclose . ', "isOpen": [] }' );
$p->set_attribute( 'data-wp-context', '{ "autoclose": ' . $autoclose . ', "isOpen": [], "icon": "' . $icon . '", "iconPosition": "' . $icon_position . '" }' );

// Only modify content if directives have been set.
$content = $p->get_updated_html();
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/accordion-header/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"example": {},
"__experimental": true,
"parent": [ "core/accordion-item" ],
"usesContext": [ "core/accordion-icon", "core/accordion-icon-position" ],
"supports": {
"anchor": true,
"color": {
Expand Down
86 changes: 18 additions & 68 deletions packages/block-library/src/accordion-header/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import clsx from 'clsx';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useEffect } from '@wordpress/element';
import {
useBlockProps,
__experimentalUseBorderProps as useBorderProps,
Expand All @@ -15,15 +16,8 @@ import {
BlockControls,
HeadingLevelDropdown,
RichText,
InspectorControls,
} from '@wordpress/block-editor';
import {
PanelBody,
ToolbarGroup,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';
import { ToolbarGroup } from '@wordpress/components';
/**
* Internal dependencies
*/
Expand All @@ -43,11 +37,24 @@ const ICONS = {
caret,
};

export default function Edit( { attributes, setAttributes } ) {
const { level, title, textAlign, icon, iconPosition, levelOptions } =
attributes;
export default function Edit( { attributes, setAttributes, context } ) {
const { level, title, textAlign, levelOptions } = attributes;
const {
'core/accordion-icon': icon,
'core/accordion-icon-position': iconPosition,
} = context;
const TagName = 'h' + level;

// Set icon attributes.
useEffect( () => {
if ( icon !== undefined && iconPosition !== undefined ) {
setAttributes( {
icon,
iconPosition,
} );
}
}, [ icon, iconPosition, setAttributes ] );

const blockProps = useBlockProps();
const borderProps = useBorderProps( attributes );
const colorProps = useColorProps( attributes );
Expand All @@ -69,63 +76,6 @@ export default function Edit( { attributes, setAttributes } ) {
/>
</ToolbarGroup>
</BlockControls>
<InspectorControls key="setting">
<PanelBody title={ __( 'Settings' ) }>
<ToggleGroupControl
__nextHasNoMarginBottom
__next40pxDefaultSize
isBlock
label={ __( 'Icon' ) }
value={ icon }
onChange={ ( value ) =>
setAttributes( { icon: value } )
}
>
<ToggleGroupControlOptionIcon
label="Plus"
icon={ plus }
value="plus"
/>
<ToggleGroupControlOptionIcon
label="Chevron"
icon={ chevron }
value="chevron"
/>
<ToggleGroupControlOptionIcon
label="Circle Plus"
icon={ circlePlus }
value="circlePlus"
/>
<ToggleGroupControlOptionIcon
label="Caret"
icon={ caret }
value="caret"
/>
<ToggleGroupControlOptionIcon
label="Chevron Right"
icon={ chevronRight }
value="chevronRight"
/>
<ToggleGroupControlOption
label="None"
value={ false }
/>
</ToggleGroupControl>
<ToggleGroupControl
__nextHasNoMarginBottom
__next40pxDefaultSize
isBlock
label={ __( 'Icon Position' ) }
value={ iconPosition }
onChange={ ( value ) => {
setAttributes( { iconPosition: value } );
} }
>
<ToggleGroupControlOption label="Left" value="left" />
<ToggleGroupControlOption label="Right" value="right" />
</ToggleGroupControl>
</PanelBody>
</InspectorControls>
<TagName
{ ...blockProps }
className={ clsx(
Expand Down
Loading