From df9c37f78d2146e821cf0349a587eb0ad5769cd8 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Sat, 14 Sep 2024 02:54:46 +0400 Subject: [PATCH 1/2] Button: Replace ButtonGroup usage with ToggleGroupControl --- packages/block-library/src/button/edit.js | 48 ++++++++++------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index 9f2a9048af4c0b..520da26ef9671e 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -16,13 +16,13 @@ import removeAnchorTag from '../utils/remove-anchor-tag'; import { __ } from '@wordpress/i18n'; import { useEffect, useState, useRef, useMemo } from '@wordpress/element'; import { - Button, - ButtonGroup, TextControl, ToolbarButton, Popover, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, + __experimentalToggleGroupControl as ToggleGroupControl, + __experimentalToggleGroupControlOption as ToggleGroupControlOption, } from '@wordpress/components'; import { AlignmentControl, @@ -115,46 +115,38 @@ function useEnter( props ) { } function WidthPanel( { selectedWidth, setAttributes } ) { - function handleChange( newWidth ) { - // Check if we are toggling the width off - const width = selectedWidth === newWidth ? undefined : newWidth; - - // Update attributes. - setAttributes( { width } ); - } - return ( { - handleChange( undefined ); - } } + resetAll={ () => setAttributes( { width: undefined } ) } > !! selectedWidth } - onDeselect={ () => handleChange( undefined ) } + onDeselect={ () => setAttributes( { width: undefined } ) } + __nextHasNoMarginBottom > - + + setAttributes( { width: newWidth } ) + } + isBlock + __next40pxDefaultSize + __nextHasNoMarginBottom + > { [ 25, 50, 75, 100 ].map( ( widthValue ) => { return ( - + value={ widthValue } + label={ `${ widthValue }%` } + /> ); } ) } - + ); From 355f9e9f03bdb265c1469684d2aa26a5c5f191a7 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 13 Dec 2024 17:57:38 +0400 Subject: [PATCH 2/2] Fix e2e tests --- test/e2e/specs/editor/blocks/buttons.spec.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/e2e/specs/editor/blocks/buttons.spec.js b/test/e2e/specs/editor/blocks/buttons.spec.js index d6b0a0a15c4ea2..c7fdc18429e11e 100644 --- a/test/e2e/specs/editor/blocks/buttons.spec.js +++ b/test/e2e/specs/editor/blocks/buttons.spec.js @@ -263,12 +263,14 @@ test.describe( 'Buttons', () => { await editor.insertBlock( { name: 'core/buttons' } ); await page.keyboard.type( 'Content' ); await editor.openDocumentSettingsSidebar(); - await page.click( - `role=region[name="Editor settings"i] >> role=tab[name="Settings"i]` - ); - await page.click( - 'role=group[name="Button width"i] >> role=button[name="25%"i]' - ); + await page + .getByRole( 'region', { name: 'Editor settings' } ) + .getByRole( 'tab', { name: 'Settings' } ) + .click(); + await page + .getByRole( 'radiogroup', { name: 'Button width' } ) + .getByRole( 'radio', { name: '25%' } ) + .click(); // Check the content. const content = await editor.getEditedPostContent();