Repository navigation
feat: add icon-only button position #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
548bf83
9a95d9f
cc78cab
585b8f7
568f923
834fc58
29fe793
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"]}}} | ||
| {"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."]}}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,10 @@ | |
| flex-direction: row-reverse; | ||
| } | ||
|
|
||
| &.blockparty-button-icon--only .block-editor-block-list__block { | ||
| pointer-events: none; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ça corrige bien le point Bugbot 👍. Effets de bord à garder en tête :
On pourrait ajouter un texte d'aide, ou masquer ce champ via un filtre Generated by Claude Code |
||
| } | ||
|
|
||
| .wp-block-icon { | ||
| display: inline-flex; | ||
| flex-shrink: 0; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
| ) } | ||
| /> | ||
| <ToggleGroupControlOption | ||
| value={ ICON_POSITION_ONLY } | ||
| label={ __( | ||
| 'Icon only', | ||
| 'blockparty-button-icon' | ||
| ) } | ||
| /> | ||
| </ToggleGroupControl> | ||
| { isIconOnly && ( | ||
| <> | ||
| <TextControl | ||
| label={ __( | ||
| 'Label (screen readers)', | ||
| 'blockparty-button-icon' | ||
| ) } | ||
| help={ __( | ||
| 'Required. Hidden on screen, announced by assistive technologies.', | ||
| 'blockparty-button-icon' | ||
| ) } | ||
| value={ plainLabel } | ||
| required | ||
| aria-invalid={ isLabelMissing } | ||
| __next40pxDefaultSize | ||
| __nextHasNoMarginBottom | ||
| onChange={ ( value ) => { | ||
| setAttributes( { | ||
| text: plainTextToButtonLabel( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note : chaque frappe remplace Generated by Claude Code |
||
| value | ||
| ), | ||
| } ); | ||
| } } | ||
| /> | ||
| { isLabelMissing && ( | ||
| <Notice | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La notice signale l'erreur mais n'empêche pas d'enregistrer. Si on veut une vraie contrainte, on peut passer par Ce n'est pas bloquant pour moi si on ajoute le fallback PHP (pas de Generated by Claude Code |
||
| status="error" | ||
| isDismissible={ false } | ||
| > | ||
| { __( | ||
| 'A label is required for an icon-only button to be accessible.', | ||
| 'blockparty-button-icon' | ||
| ) } | ||
| </Notice> | ||
| ) } | ||
| </> | ||
| ) } | ||
| <Button | ||
| variant="secondary" | ||
| __next40pxDefaultSize | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * Converts the button rich-text label to plain text (for a TextControl). | ||
| * | ||
| * Uses DOMParser so the markup is parsed in an inert document (no script or | ||
| * resource loading). | ||
| * | ||
| * @param {string|undefined} html Rich-text HTML. | ||
| * @return {string} Plain text. | ||
| */ | ||
| export function getButtonLabelPlainText( html ) { | ||
| if ( ! html ) { | ||
| return ''; | ||
| } | ||
|
|
||
| const doc = new window.DOMParser().parseFromString( | ||
| `<body>${ html }</body>`, | ||
| 'text/html' | ||
| ); | ||
|
|
||
| return doc.body.textContent || ''; | ||
| } | ||
|
|
||
| /** | ||
| * Escapes plain text so it can be stored in the rich-text `text` attribute. | ||
| * | ||
| * @param {string} text Plain text typed by the editor. | ||
| * @return {string} HTML-safe text. | ||
| */ | ||
| export function plainTextToButtonLabel( text ) { | ||
| return ( text || '' ) | ||
| .replace( /&/g, '&' ) | ||
| .replace( /</g, '<' ) | ||
| .replace( />/g, '>' ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Régression sur les boutons v1.0.0 sans libellé
Ce filtre tourne au rendu, donc sur tout le contenu déjà publié, sans réenregistrement. Un bouton v1.0.0 avec icône + libellé vide +
aria-labelsur l'icône (le seul moyen de faire une icône seule avant cette PR) devient un lien sans nom accessible.Suggestion : ne poser
aria-hiddenque si le libellé a du texte. Le plus simple est probablement de le faire dansleave_button_with_icon_context()(le filtrerender_block_core/button), où tu as le HTML complet du bouton : tu vérifies que.wp-block-button__labeln'est pas vide (par exemple avectrim( wp_strip_all_tags( … ) )sur le contenu du span, ou avecWP_HTML_Processor), puis tu posesaria-hiddensur.wp-block-icon. Sinon, tu laisses l'icône telle quelle. Ça règle aussi le cas « icône seule + libellé vide » (point 3 de la review).Un test PHPUnit sur ce cas serait bienvenu.
Generated by Claude Code