From 548bf83681bcb34e42db57da438aa97879af164f Mon Sep 17 00:00:00 2001 From: Milan Ricoul Date: Tue, 20 Oct 2026 17:31:44 +0200 Subject: [PATCH 1/4] chore: add plugin-data --- .plugin-data | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .plugin-data diff --git a/.plugin-data b/.plugin-data new file mode 100644 index 0000000..5640207 --- /dev/null +++ b/.plugin-data @@ -0,0 +1,4 @@ +{ + "version": "0.0.1", + "slug": "blockparty-button-icon" +} From cc78cab3bd35c77bdf1776f9e3bf62e3ccdda1e1 Mon Sep 17 00:00:00 2001 From: Milan Ricoul Date: Tue, 20 Oct 2026 17:41:27 +0200 Subject: [PATCH 2/4] Revert "chore: add plugin-data" --- .plugin-data | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .plugin-data diff --git a/.plugin-data b/.plugin-data deleted file mode 100644 index 5640207..0000000 --- a/.plugin-data +++ /dev/null @@ -1,4 +0,0 @@ -{ - "version": "0.0.1", - "slug": "blockparty-button-icon" -} From 834fc582ec0ac1b98a18ed4c5e39405695f776a7 Mon Sep 17 00:00:00 2001 From: Raphael Sanchez Date: Wed, 18 Nov 2026 19:44:11 +0100 Subject: [PATCH 3/4] feat: add icon-only button position Add a third icon position, "Icon only": the label stays in the markup, visually hidden, so links and buttons keep an accessible name. In the editor the label is hidden from the canvas and edited from a required sidebar field, with an error notice when it is empty. Icons rendered inside buttons now get aria-hidden="true" since the text label always provides the accessible name. Saved markup for existing buttons (no icon, left, right) is unchanged, so no deprecation is needed; an E2E test loads v1.0.0 markup to check it. Refs Redmine #92801 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 ++ README.md | 18 ++++- classes/IconBlockRenderer.php | 33 +++++++- ...r_FR-dfbff627e6c248bcb3b61d7d06da9ca9.json | 2 +- languages/blockparty-button-icon-fr_FR.mo | Bin 1213 -> 1712 bytes languages/blockparty-button-icon-fr_FR.po | 16 ++++ languages/blockparty-button-icon.pot | 20 ++++- readme.txt | 2 +- .../button-icon-controls.jsx | 61 +++++++++++++- .../button-label-plain-text.js | 34 ++++++++ src/extend-core-button/constants.js | 2 + .../edit-with-icon-toolbar.jsx | 3 +- src/extend-core-button/edit.jsx | 66 ++++++--------- .../get-button-icon-class-names.js | 23 ++++++ src/extend-core-button/save.jsx | 11 +-- src/style.scss | 19 +++++ tests/js/button-label-plain-text.test.js | 35 ++++++++ tests/js/get-button-icon-class-names.test.js | 40 ++++++++++ tests/php/IconBlockRendererTest.php | 32 +++++++- .../specs/editor-button-icon.spec.js | 75 ++++++++++++++++++ .../specs/frontend-button-icon.spec.js | 29 ++++++- 21 files changed, 464 insertions(+), 62 deletions(-) create mode 100644 src/extend-core-button/button-label-plain-text.js create mode 100644 src/extend-core-button/get-button-icon-class-names.js create mode 100644 tests/js/button-label-plain-text.test.js create mode 100644 tests/js/get-button-icon-class-names.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bfb3a1..c15c3d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ 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). +## Unreleased + +- Add an **Icon only** position: the label is visually hidden but kept for screen readers, and edited from a required sidebar field +- Mark icons rendered inside buttons as decorative (`aria-hidden="true"`) + ## 1.0.0 - 2026-10-15 - Initial release diff --git a/README.md b/README.md index faaa860..82e179e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Extend the WordPress **core Button** block (`core/button`) with optional icons, - **Core block extension**: No new block name — editors keep using the familiar Button block - **Optional icon**: Insert an icon as an inner block (defaults to `core/icon` on WordPress 7.0+) -- **Icon position**: Display the icon to the left or right of the label +- **Icon position**: Display the icon to the left or right of the label, or show the icon only (label kept for screen readers) - **Block gap**: Control horizontal spacing between icon and text via block spacing settings - **Valid markup**: Icons render inside links with a `span` wrapper on the front end (phrasing content) - **Extensible**: Filter which icon block types may be inserted into a button @@ -42,7 +42,8 @@ composer require beapi/blockparty-button-icon 1. Add or select a **Button** block in the editor 2. Open the block **Styles** panel (sidebar) 3. Turn on **Show icon** -4. Choose **Left** or **Right** for icon position +4. Choose **Left**, **Right** or **Icon only** for icon position + - With **Icon only**, the label is hidden in the canvas and on the front end; fill the required **Label (screen readers)** field in the sidebar 5. Use the block toolbar **Icon** control to pick or replace the icon 6. Adjust **Block spacing → Block gap** (horizontal) to change the space between icon and label @@ -67,6 +68,8 @@ The first block type in the filtered list is used when the editor creates a new - Button label text is wrapped in `` when an icon is present, keeping a clear text node for assistive technologies - On the front end, `core/icon` outer wrappers are output as `span` elements when rendered inside button links +- Icons inside buttons get `aria-hidden="true"`: the text label always provides the accessible name +- **Icon only** buttons keep the label in the markup and hide it visually (`.blockparty-button-icon--only .wp-block-button__label`), so links and buttons keep an accessible name ## Generated markup example @@ -79,6 +82,17 @@ The first block type in the filtered list is used when the editor creates a new ``` +Icon only: + +```html + +``` + ## Development ### Prerequisites diff --git a/classes/IconBlockRenderer.php b/classes/IconBlockRenderer.php index 0df8973..e66188f 100644 --- a/classes/IconBlockRenderer.php +++ b/classes/IconBlockRenderer.php @@ -8,7 +8,8 @@ namespace Blockparty\ButtonIcon; /** - * Converts core/icon wrappers so markup stays valid inside button links. + * Converts core/icon wrappers so markup stays valid inside button links + * and marks them as decorative. */ class IconBlockRenderer { @@ -102,7 +103,35 @@ public function render_icon_as_span( string $block_content, array $block ): stri return $block_content; } - return self::convert_icon_wrapper_to_span( $block_content ); + return self::hide_icon_from_assistive_technologies( + self::convert_icon_wrapper_to_span( $block_content ) + ); + } + + /** + * Marks the icon wrapper as decorative (aria-hidden="true"). + * + * Inside a button the text label always provides the accessible name, even + * when it is visually hidden (icon only). An icon aria-label would otherwise + * be announced in addition to the label. + * + * @param string $html Rendered icon block HTML. + * @return string HTML with aria-hidden on the icon wrapper when applicable. + */ + public static function hide_icon_from_assistive_technologies( string $html ): string { + $processor = new \WP_HTML_Tag_Processor( $html ); + + if ( ! $processor->next_tag( array( 'class_name' => 'wp-block-icon' ) ) ) { + return $html; + } + + if ( 'true' === $processor->get_attribute( 'aria-hidden' ) ) { + return $html; + } + + $processor->set_attribute( 'aria-hidden', 'true' ); + + return $processor->get_updated_html(); } /** diff --git a/languages/blockparty-button-icon-fr_FR-dfbff627e6c248bcb3b61d7d06da9ca9.json b/languages/blockparty-button-icon-fr_FR-dfbff627e6c248bcb3b61d7d06da9ca9.json index e64d3a5..9286383 100644 --- a/languages/blockparty-button-icon-fr_FR-dfbff627e6c248bcb3b61d7d06da9ca9.json +++ b/languages/blockparty-button-icon-fr_FR-dfbff627e6c248bcb3b61d7d06da9ca9.json @@ -1 +1 @@ -{"translation-revision-date":"2026-10-15 22:34+0200","generator":"WP-CLI\/2.11.0","source":"build\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr_FR","plural-forms":"nplurals=2; plural=(n != 1);"},"Remove icon":["Retirer l\u2019ic\u00f4ne"],"Icon":["Ic\u00f4ne"],"Show icon":["Afficher l\u2019ic\u00f4ne"],"Icon position":["Position de l\u2019ic\u00f4ne"],"Left":["Gauche"],"Right":["Droite"],"Replace Icon":["Remplacer l\u2019ic\u00f4ne"],"Mark as nofollow":["Marquer en nofollow"],"Button text":["Texte du bouton"],"Add text\u2026":["Ajouter du texte\u2026"],"Link":["Lien"]}}} \ No newline at end of file +{"translation-revision-date":"2026-10-15 22:34+0200","generator":"WP-CLI\/2.12.0","source":"build\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr_FR","plural-forms":"nplurals=2; plural=(n != 1);"},"Remove icon":["Retirer l\u2019ic\u00f4ne"],"Icon":["Ic\u00f4ne"],"Show icon":["Afficher l\u2019ic\u00f4ne"],"Icon position":["Position de l\u2019ic\u00f4ne"],"Left":["Gauche"],"Right":["Droite"],"Replace Icon":["Remplacer l\u2019ic\u00f4ne"],"Mark as nofollow":["Marquer en nofollow"],"Button text":["Texte du bouton"],"Add text\u2026":["Ajouter du texte\u2026"],"Link":["Lien"],"Icon only":["Ic\u00f4ne seule"],"Label (screen readers)":["Libell\u00e9 (lecteurs d\u2019\u00e9cran)"],"Required. Hidden on screen, announced by assistive technologies.":["Obligatoire. Masqu\u00e9 \u00e0 l\u2019\u00e9cran, annonc\u00e9 par les technologies d\u2019assistance."],"A label is required for an icon-only button to be accessible.":["Un libell\u00e9 est obligatoire pour qu\u2019un bouton ic\u00f4ne seule soit accessible."]}}} \ No newline at end of file diff --git a/languages/blockparty-button-icon-fr_FR.mo b/languages/blockparty-button-icon-fr_FR.mo index d9826be6f04aef1da3bacfebf20ce48191295107..4fd63b0c827e8bc3a8a19aebafc05643f234865a 100644 GIT binary patch delta 909 zcmY+A&uSA<6vl7et|C-Eh3B+mS z400ctM^;mKAijdP!Eay={0p7|b7>)_!3!Xt-vqCK_rWX}fg@lG90Om0tbg6Vf8S$U z?BV4UEA;w8)F2$Y_cTd6Hb;m)0sTNJ}RfO>GodA}SEmnz1TUMvH2<=A89IDK!ea zbs5@1vYEPZr{Bb(hpJx3B|huPE~BS5vG(D>Ymti{Hd5=7BI&=-CNK>pt&{vnZ4N(P zEH2A+Ws`}_RF2B!`D@oNmCB`3vXXu>UUhXNb{le@R>S8HmXp2oO7b#utM*h=pfGCC z*(GTsGG3q>Ze%brjK?80iqQT@C{9R@{R~aahh3vW6 z>S6i0K>Cr4LrZm(?CkoXs|(4qY-MS2(A1%tYnw6Lbly^Mr0cCg`#4{7Lkgt*Zvowk Oz1_H2m6PmbXZ`^W;Kv34 delta 430 zcmYk$Jxjwt7zgmHNs7frrD{=pA$twI1ndy%AT0$aOX$=^LcP=jNhFPnON)z>i)ROQ z5M0#B4vuwla?wf9#la8Y2XH9<4+47d-0z;}-kyQ}nCX7z)IPzOLM$Q9WP*`R{W*c9 zj(iR-z&tEMS+Bt&bfF55pbn3dyq|ahr%}Ix^4z3jFrTSaw^^xS2${OwZ7FbD-rYLrdjo3<`_1$OQuClYpr2Z$Fd!27btZo757R( z584M_8>jqeyXFd^mc_DmnXf1B8#~O{`|6$Z*3(14#E-VQSdBs+GqU0PytT`sf7|32 D-^Wf3 diff --git a/languages/blockparty-button-icon-fr_FR.po b/languages/blockparty-button-icon-fr_FR.po index c040d61..083035c 100644 --- a/languages/blockparty-button-icon-fr_FR.po +++ b/languages/blockparty-button-icon-fr_FR.po @@ -74,3 +74,19 @@ msgstr "Ajouter du texte…" #: build/index.js:1 msgid "Link" msgstr "Lien" + +#: build/index.js:1 +msgid "Icon only" +msgstr "Icône seule" + +#: build/index.js:1 +msgid "Label (screen readers)" +msgstr "Libellé (lecteurs d’écran)" + +#: build/index.js:1 +msgid "Required. Hidden on screen, announced by assistive technologies." +msgstr "Obligatoire. Masqué à l’écran, annoncé par les technologies d’assistance." + +#: build/index.js:1 +msgid "A label is required for an icon-only button to be accessible." +msgstr "Un libellé est obligatoire pour qu’un bouton icône seule soit accessible." diff --git a/languages/blockparty-button-icon.pot b/languages/blockparty-button-icon.pot index a45bc42..c617be2 100644 --- a/languages/blockparty-button-icon.pot +++ b/languages/blockparty-button-icon.pot @@ -9,9 +9,9 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2026-10-15T20:12:02+00:00\n" +"POT-Creation-Date: 2026-11-18T18:31:44+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-button-icon\n" #. Plugin Name of the plugin @@ -58,6 +58,22 @@ msgstr "" msgid "Right" msgstr "" +#: build/index.js:1 +msgid "Icon only" +msgstr "" + +#: build/index.js:1 +msgid "Label (screen readers)" +msgstr "" + +#: build/index.js:1 +msgid "Required. Hidden on screen, announced by assistive technologies." +msgstr "" + +#: build/index.js:1 +msgid "A label is required for an icon-only button to be accessible." +msgstr "" + #: build/index.js:1 msgid "Replace Icon" msgstr "" diff --git a/readme.txt b/readme.txt index 7cd2711..ca62b71 100644 --- a/readme.txt +++ b/readme.txt @@ -18,7 +18,7 @@ Blockparty Button Icon enhances the WordPress core Button block (`core/button`) * Extends the core Button block (no new block name) * Optional icon via inner blocks (defaults to `core/icon`) -* Icon position: left or right +* Icon position: left, right or icon only (label kept for screen readers) * Horizontal block gap for icon ↔ label spacing * Valid HTML inside links (`span` wrapper for icons on the front end) * Filter `blockparty_button_icon_allowed_icon_blocks` to allow other icon block types diff --git a/src/extend-core-button/button-icon-controls.jsx b/src/extend-core-button/button-icon-controls.jsx index 73ecf35..1a28699 100644 --- a/src/extend-core-button/button-icon-controls.jsx +++ b/src/extend-core-button/button-icon-controls.jsx @@ -5,17 +5,27 @@ import { Button, ToolbarButton, ToolbarGroup, + Notice, PanelBody, + TextControl, ToggleControl, // eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- ToggleGroupControl is not yet a stable export in @wordpress/components. __experimentalToggleGroupControl as ToggleGroupControl, // eslint-disable-next-line @wordpress/no-unsafe-wp-apis __experimentalToggleGroupControlOption as ToggleGroupControlOption, } from '@wordpress/components'; -import { ICON_POSITION_LEFT, ICON_POSITION_RIGHT } from './constants'; +import { + ICON_POSITION_LEFT, + ICON_POSITION_ONLY, + ICON_POSITION_RIGHT, +} from './constants'; import IconToolbarSvg from './icon-toolbar-svg'; import { getInnerIconClientId } from './get-inner-icon-client-id'; import { openIconInserterForBlock } from './open-icon-inserter'; +import { + getButtonLabelPlainText, + plainTextToButtonLabel, +} from './button-label-plain-text'; /** * Toolbar and inspector controls for button icons. @@ -25,6 +35,7 @@ import { openIconInserterForBlock } from './open-icon-inserter'; * @param {string} props.iconPosition Icon position relative to label. * @param {boolean} props.hasIconBlock Whether core/icon is available. * @param {string} props.clientId Button block client id. + * @param {string} [props.text] Button label (rich-text HTML). * @param {( attributes: Object ) => void} props.setAttributes Attribute updater. * @return {Element} Controls fragment. */ @@ -33,12 +44,16 @@ export default function ButtonIconControls( { iconPosition, hasIconBlock, clientId, + text, setAttributes, } ) { const iconClientId = useSelect( ( select ) => getInnerIconClientId( select, clientId ), [ clientId ] ); + const isIconOnly = hasIcon && iconPosition === ICON_POSITION_ONLY; + const plainLabel = getButtonLabelPlainText( text ); + const isLabelMissing = isIconOnly && '' === plainLabel.trim(); return ( <> @@ -105,7 +120,51 @@ export default function ButtonIconControls( { 'blockparty-button-icon' ) } /> + + { isIconOnly && ( + <> +