Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 45 additions & 0 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,51 @@ This page lists the blocks included in the block-library package.

<!-- START TOKEN Autogenerated - DO NOT EDIT -->

## Accordion Header

Accordion header. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/accordion-header))

- **Name:** core/accordion-header
- **Experimental:** true
- **Category:** design
- **Parent:** core/accordion-item
- **Supports:** anchor, border, color (background, gradient, text), interactivity, shadow, spacing (margin, padding), typography (fontSize, textAlign), ~~align~~
- **Attributes:** iconPosition, level, levelOptions, openByDefault, showIcon, textAlignment, title

## Accordion

A single accordion that displays a header and expandable content. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/accordion-item))

- **Name:** core/accordion-item
- **Experimental:** true
- **Category:** design
- **Parent:** core/accordions
- **Allowed Blocks:** core/accordion-header, core/accordion-panel
- **Supports:** align (full, wide), color (background, gradient, text), interactivity, shadow, spacing (blockGap, margin)
- **Attributes:** openByDefault

## Accordion Panel

Accordion Panel ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/accordion-panel))

- **Name:** core/accordion-panel
- **Experimental:** true
- **Category:** design
- **Parent:** core/accordion-item
- **Supports:** border, color (background, gradient, text), interactivity, shadow, spacing (blockGap, margin, padding), typography (fontSize, lineHeight)
- **Attributes:** allowedBlocks, isSelected, openByDefault, templateLock

## Accordions

A group of Accordion headers and associated expandable content. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/accordions))

- **Name:** core/accordions
- **Experimental:** true
- **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, showIcon

## Archives

Display a date archive of your posts. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/archives))
Expand Down
4 changes: 4 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function gutenberg_reregister_core_block_types() {
$blocks_dirs = array(
__DIR__ . '/../build/block-library/blocks/' => array(
'block_folders' => array(
'accordion-header',
'accordion-panel',
'audio',
'button',
'buttons',
Expand Down Expand Up @@ -44,6 +46,8 @@ function gutenberg_reregister_core_block_types() {
'embed',
),
'block_names' => array(
'accordion-item.php' => 'core/accordion-item',
'accordions.php' => 'core/accordions',
'archives.php' => 'core/archives',
'avatar.php' => 'core/avatar',
'block.php' => 'core/block',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"react-native": "src/index",
"wpScript": true,
"wpScriptModuleExports": {
"./accordions/view": "./build-module/accordions/view.js",
"./file/view": "./build-module/file/view.js",
"./form/view": "./build-module/form/view.js",
"./image/view": "./build-module/image/view.js",
Expand Down
93 changes: 93 additions & 0 deletions packages/block-library/src/accordion-header/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "core/accordion-header",
"version": "0.1.0",
"title": "Accordion Header",
"category": "design",
"description": "Accordion header.",
"example": {},
"__experimental": true,
"parent": [ "core/accordion-item" ],
"usesContext": [
"core/accordion-icon-position",
"core/accordion-show-icon"
],
"supports": {
"anchor": true,
"color": {
"background": true,
"gradient": true
},
"align": false,
"border": true,
"interactivity": true,
"spacing": {
"padding": true,
"margin": [ "top", "bottom" ],
"__experimentalDefaultControls": {
"padding": true,
"margin": true
}
},
"__experimentalBorder": {
"color": true,
"radius": true,
"style": true,
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"style": true,
"width": true
}
},
"typography": {
"textAlign": true,
"fontSize": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true,
"fontFamily": true
}
},
"shadow": true
},
"attributes": {
"openByDefault": {
"type": "boolean",
"default": false
},
"title": {
"type": "rich-text",
"source": "rich-text",
"selector": "span"
},
"level": {
"type": "number",
"default": 3
},
"levelOptions": {
"type": "array"
},
"textAlignment": {
"type": "string",
"default": "left"
},
"iconPosition": {
"type": "string",
"enum": [ "left", "right" ],
"default": "right"
},
"showIcon": {
"type": "boolean",
"default": true
}
},
"textdomain": "default"
}
128 changes: 128 additions & 0 deletions packages/block-library/src/accordion-header/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useEffect } from '@wordpress/element';
import {
useBlockProps,
__experimentalUseBorderProps as useBorderProps,
__experimentalUseColorProps as useColorProps,
__experimentalGetSpacingClassesAndStyles as useSpacingProps,
__experimentalGetShadowClassesAndStyles as useShadowProps,
BlockControls,
HeadingLevelDropdown,
RichText,
} from '@wordpress/block-editor';
import { ToolbarGroup } from '@wordpress/components';
/**
* Internal dependencies
*/
import { plus } from '../accordion-item/icons';

const ICONS = {
plus,
};

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

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

const blockProps = useBlockProps();
const borderProps = useBorderProps( attributes );
const colorProps = useColorProps( attributes );
const spacingProps = useSpacingProps( attributes );
const shadowProps = useShadowProps( attributes );

const Icon = ICONS.plus;
const shouldShowIcon = showIcon && Icon;

return (
<>
<BlockControls>
<ToolbarGroup>
<HeadingLevelDropdown
value={ level }
options={ levelOptions }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
</ToolbarGroup>
</BlockControls>
<TagName
{ ...blockProps }
className={ clsx(
blockProps.className,
colorProps.className,
borderProps.className,
'accordion-item__heading',
{
[ `has-custom-font-size` ]: blockProps.style.fontSize,
[ `icon-position-left` ]: iconPosition === 'left',
[ `has-text-align-${ textAlign }` ]: textAlign,
}
) }
style={ {
...borderProps.style,
...colorProps.style,
...shadowProps.style,
} }
>
<button
className={ clsx( 'accordion-item__toggle' ) }
style={ {
...spacingProps.style,
} }
>
<RichText
allowedFormats={ [
'core/bold',
'core/italic',
'core/image',
'core/strikethrough',
] }
disableLineBreaks
tagName="span"
value={ title }
onChange={ ( newTitle ) =>
setAttributes( { title: newTitle } )
}
placeholder={ __( 'Accordion title' ) }
/>
{ shouldShowIcon && (
<span
className={ clsx( `accordion-item__toggle-icon`, {
'has-icon-plus': true,
} ) }
style={ {
// TO-DO: make this configurable
width: `1.2em`,
height: `1.2em`,
} }
>
{ Icon && <Icon width="1.2em" height="1.2em" /> }
</span>
) }
</button>
</TagName>
</>
);
}
24 changes: 24 additions & 0 deletions packages/block-library/src/accordion-header/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* WordPress dependencies
*/
import { accordionHeader } from '@wordpress/icons';
/**
* Internal dependencies
*/
import edit from './edit';
import save from './save';
import metadata from './block.json';
import initBlock from '../utils/init-block';

const { name } = metadata;

export { metadata, name };

export const settings = {
icon: accordionHeader,
example: {},
edit,
save,
};

export const init = () => initBlock( { name, metadata, settings } );
6 changes: 6 additions & 0 deletions packages/block-library/src/accordion-header/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Internal dependencies
*/
import { init } from './';

export default init();
Loading
Loading