Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .plugin-data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.7",
"version": "1.0.8",
"slug": "blockparty-accordion"
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.8 - 2026-02-09

- Add option to open the first item by default

## 1.0.7 - 2026-02-02

- Update `@beapi/be-a11y` to `1.7.3`
Expand Down
35 changes: 33 additions & 2 deletions blockparty-accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Accessible Accordion block for WordPress editor.
* Requires at least: 6.2
* Requires PHP: 8.1
* Version: 1.0.7
* Version: 1.0.8
* Author: Be API Technical team
* Author URI: https://beapi.fr
* License: GPL-2.0-or-later
Expand All @@ -15,7 +15,7 @@

namespace Blockparty\Accordion;

define( 'BLOCKPARTY_ACCORDION_VERSION', '1.0.7' );
define( 'BLOCKPARTY_ACCORDION_VERSION', '1.0.8' );
define( 'BLOCKPARTY_ACCORDION_URL', plugin_dir_url( __FILE__ ) );
define( 'BLOCKPARTY_ACCORDION_DIR', plugin_dir_path( __FILE__ ) );
define( 'BLOCKPARTY_ACCORDION_PLUGIN_DIRNAME', plugin_basename( __FILE__ ) );
Expand Down Expand Up @@ -70,5 +70,36 @@ function allow_aria_attributes( $tags, $context ) {
return $tags;
}

/**
* Set first accordion trigger to aria-expanded="true" when block has firstItemOpenByDefault.
*
* Done server-side for LCP: the BeAPI a11y JS library would set it on load, but that would cause a visible
* layout shift (first panel hidden then shown). Outputting the correct state in HTML
* avoids that shift. The summary block cannot know it is the first item, so it always
* outputs aria-expanded="false"; this filter corrects the first trigger only.
*
* @param string $block_content The block content.
* @param array $block The full block, including blockName and attrs.
* @return string Filtered block content.
*/
function render_accordion_first_item_expanded( $block_content, $block ) {
if ( ( $block['blockName'] ?? '' ) !== 'blockparty/accordion' ) {
return $block_content;
}
$first_open = $block['attrs']['firstItemOpenByDefault'] ?? false;
if ( ! $first_open ) {
return $block_content;
}
// Replace only the first occurrence (first trigger) so the first item is expanded.
$block_content = preg_replace(
'/aria-expanded="false"/',
'aria-expanded="true"',
$block_content,
1
);
return $block_content;
}

add_action( 'init', __NAMESPACE__ . '\\init' );
add_filter( 'wp_kses_allowed_html', __NAMESPACE__ . '\\allow_aria_attributes', 10, 2 );
add_filter( 'render_block', __NAMESPACE__ . '\\render_accordion_first_item_expanded', 10, 2 );
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2026-02-09 10:51+0100","generator":"WP-CLI\/2.12.0","source":"build\/blockparty-accordion\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr","plural-forms":"nplurals=2; plural=(n != 1);"},"Accordion options":["Options de l\u2019accord\u00e9on"],"Open first item by default":["Ouvrir le premier \u00e9l\u00e9ment par d\u00e9faut"]}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2025-11-07 16:32+0100","generator":"WP-CLI\/2.11.0","source":"build\/blockparty-accordion-summary\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr","plural-forms":"nplurals=2; plural=(n != 1);"},"Icon":["Ic\u00f4ne"],"Summary\u2026":["Titre\u2026"]}}}
{"translation-revision-date":"2026-02-09 10:51+0100","generator":"WP-CLI\/2.12.0","source":"build\/blockparty-accordion-summary\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr","plural-forms":"nplurals=2; plural=(n != 1);"},"Icon":["Ic\u00f4ne"],"Summary\u2026":["Titre\u2026"]}}}
Binary file modified languages/blockparty-accordion-fr_FR.mo
Binary file not shown.
14 changes: 11 additions & 3 deletions languages/blockparty-accordion-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ msgstr ""
"Project-Id-Version: Blockparty Accordion 1.0.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/blockparty-"
"accordion\n"
"POT-Creation-Date: 2025-11-07T15:31:42+00:00\n"
"PO-Revision-Date: 2025-11-07 16:32+0100\n"
"POT-Creation-Date: 2026-02-09T09:49:54+00:00\n"
"PO-Revision-Date: 2026-02-09 10:51+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.8\n"
"X-Generator: Poedit 3.1.1\n"
"X-Domain: blockparty-accordion\n"

#. Plugin Name of the plugin
Expand Down Expand Up @@ -44,6 +44,14 @@ msgstr "Icône"
msgid "Summary…"
msgstr "Titre…"

#: build/blockparty-accordion/index.js:1
msgid "Accordion options"
msgstr "Options de l’accordéon"

#: build/blockparty-accordion/index.js:1
msgid "Open first item by default"
msgstr "Ouvrir le premier élément par défaut"

#: build/blockparty-accordion-item/block.json
msgctxt "block title"
msgid "Item"
Expand Down
16 changes: 12 additions & 4 deletions languages/blockparty-accordion.pot
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright (C) 2025 Be API Technical team
# Copyright (C) 2026 Be API Technical team
# This file is distributed under the GPL-2.0-or-later.
msgid ""
msgstr ""
"Project-Id-Version: Blockparty Accordion 1.0.4\n"
"Project-Id-Version: Blockparty Accordion 1.0.8\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/blockparty-accordion\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2025-11-07T15:31:42+00:00\n"
"POT-Creation-Date: 2026-02-09T09:49:54+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.11.0\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: blockparty-accordion\n"

#. Plugin Name of the plugin
Expand Down Expand Up @@ -42,6 +42,14 @@ msgstr ""
msgid "Summary…"
msgstr ""

#: build/blockparty-accordion/index.js:1
msgid "Accordion options"
msgstr ""

#: build/blockparty-accordion/index.js:1
msgid "Open first item by default"
msgstr ""

#: build/blockparty-accordion-item/block.json
msgctxt "block title"
msgid "Item"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockparty-accordion",
"version": "1.0.7",
"version": "1.0.8",
"description": "Accessible Accordion block for WordPress",
"author": "Be API Technical team",
"license": "GPL-2.0-or-later",
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove

== Changelog ==

= 1.0.8 =

* Add option to open the first item by default

= 1.0.7 =

* Update block icons
Expand Down
11 changes: 8 additions & 3 deletions src/blockparty-accordion-item/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "blockparty/accordion-item",
"parent": [ "blockparty/accordion" ],
"version": "1.0.7",
"parent": [
"blockparty/accordion"
],
"version": "1.0.8",
"title": "Item",
"category": "widgets",
"description": "Accessible accordion block item.",
"supports": {
"html": false,
"anchor": false,
"align": [ "wide", "full" ],
"align": [
"wide",
"full"
],
"reusable": false,
"color": {
"background": true,
Expand Down
11 changes: 8 additions & 3 deletions src/blockparty-accordion-panel/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "blockparty/accordion-panel",
"parent": [ "blockparty/accordion-item" ],
"version": "1.0.7",
"parent": [
"blockparty/accordion-item"
],
"version": "1.0.8",
"title": "Panel",
"category": "widgets",
"description": "Accessible accordion block panel.",
"supports": {
"html": false,
"anchor": false,
"align": [ "wide", "full" ],
"align": [
"wide",
"full"
],
"reusable": false,
"color": {
"background": true,
Expand Down
11 changes: 8 additions & 3 deletions src/blockparty-accordion-summary/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "blockparty/accordion-summary",
"parent": [ "blockparty/accordion-item" ],
"version": "1.0.7",
"parent": [
"blockparty/accordion-item"
],
"version": "1.0.8",
"title": "Summary",
"category": "widgets",
"description": "Accessible accordion block summary.",
"supports": {
"html": false,
"anchor": false,
"align": [ "wide", "full" ],
"align": [
"wide",
"full"
],
"lock": true,
"reusable": false,
"color": {
Expand Down
13 changes: 11 additions & 2 deletions src/blockparty-accordion/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "blockparty/accordion",
"version": "1.0.7",
"version": "1.0.8",
"title": "Accordion",
"category": "widgets",
"description": "Accessible accordion block.",
"attributes": {
"firstItemOpenByDefault": {
"type": "boolean",
"default": false
}
},
"supports": {
"html": false,
"anchor": true,
"align": [ "wide", "full" ],
"align": [
"wide",
"full"
],
"color": {
"background": true,
"text": true
Expand Down
33 changes: 30 additions & 3 deletions src/blockparty-accordion/edit.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import {
useBlockProps,
useInnerBlocksProps,
InspectorControls,
} from '@wordpress/block-editor';
import { PanelBody, ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import './editor.scss';

const BLOCKS_CHILD = 'blockparty/accordion-item';
const ALLOWED_BLOCKS = [BLOCKS_CHILD];

export default function Edit() {
export default function Edit({ attributes, setAttributes }) {
const { firstItemOpenByDefault } = attributes;
const blockProps = useBlockProps();
const innerBlocksProps = useInnerBlocksProps(blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
template: [[BLOCKS_CHILD], [BLOCKS_CHILD], [BLOCKS_CHILD]],
});
return <div {...innerBlocksProps} />;
return (
<>
<InspectorControls>
<PanelBody
title={__('Accordion options', 'blockparty-accordion')}
>
<ToggleControl
label={__(
'Open first item by default',
'blockparty-accordion'
)}
checked={firstItemOpenByDefault}
onChange={(value) =>
setAttributes({ firstItemOpenByDefault: value })
}
/>
</PanelBody>
</InspectorControls>
<div {...innerBlocksProps} />
</>
);
}
5 changes: 5 additions & 0 deletions src/blockparty-accordion/editor.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* editor */
.wp-block-blockparty-accordion {

&-item,
&-panel,
.wp-block {
Expand All @@ -12,6 +13,10 @@
margin-bottom: 0;
}

&-panel {
display: none;
}

&-item.has-child-selected .wp-block-blockparty-accordion-panel {
display: block;
}
Expand Down
10 changes: 8 additions & 2 deletions src/blockparty-accordion/save.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';

export default function save() {
const innerBlocksProps = useInnerBlocksProps.save(useBlockProps.save());
export default function save({ attributes }) {
const { firstItemOpenByDefault } = attributes;
const blockProps = useBlockProps.save({
'data-first-item-open-by-default': firstItemOpenByDefault
? 'true'
: undefined,
});
const innerBlocksProps = useInnerBlocksProps.save(blockProps);
return <div {...innerBlocksProps} />;
}
12 changes: 10 additions & 2 deletions src/blockparty-accordion/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import { Accordion } from '@beapi/be-a11y';
// eslint-disable-next-line no-undef
const accordionConfig = beapiAccordionBlock.accordionConfig;

// Initialize beapi-accordion
// Initialize beapi-accordion (closedDefault from block option firstItemOpenByDefault)
window.addEventListener('load', function () {
Accordion.init('.wp-block-blockparty-accordion', accordionConfig);
const selector = '.wp-block-blockparty-accordion';
const elements = document.querySelectorAll(selector);
elements.forEach((el) => {
const config = { ...accordionConfig };
if (el.dataset.firstItemOpenByDefault === 'true') {
config.closedDefault = false;
}
Accordion.init(el, config);
});
});
2 changes: 1 addition & 1 deletion src/blockparty-accordion/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
}

&-panel {
&-item:where(:has([aria-expanded="false"])) &-panel {
display: none;
}

Expand Down
Loading