Skip to content
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

updates LayoutTypeSwitcher to use ToggleGroupControl #65498

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

spadeshoe
Copy link
Contributor

@spadeshoe spadeshoe commented Sep 19, 2024

What?

PR replaces the ButtonGroup component with ToggleGroupControl in the LayoutTypeSwitcher component

Why?

Part Of -#65339

How?

Updates LayoutTypeSwitcher to use the new ToggleGroupControl in lieu of ButtonGroup component

Testing Instructions

Note: the LayoutTypeSwitcher function is no longer used in any core blocks. You will need to adjust the conditional on line 267 to make the controls visible on the block.

! inherit && allowSwitching && to true &&

  1. Create a new post or page
  2. Place a block that has layout controls, such as Group or Cover
  3. Block controls should be visible and functional. See screenshot.
Screenshot 2024-09-19 at 8 24 30 AM

Testing Instructions for Keyboard

Same as above

Screenshots or screencast

Copy link

github-actions bot commented Sep 19, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: spadeshoe <spdft@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Sep 19, 2024
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @spadeshoe! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@mirka mirka added [Type] Enhancement A suggestion for improvement. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block editor /packages/block-editor Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Sep 24, 2024
@mirka mirka requested a review from a team September 24, 2024 06:48
Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work here!

Comment on lines 328 to 330
<ToggleGroupControlOption
value={ name }
label={ name }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the component APIs are used a bit incorrectly. We'll need the following changes to keep it in sync with the block variation, and for the options to have the correct labels.

diff --git a/packages/block-editor/src/hooks/layout.js b/packages/block-editor/src/hooks/layout.js
index f437a82ac1..90859e5e43 100644
--- a/packages/block-editor/src/hooks/layout.js
+++ b/packages/block-editor/src/hooks/layout.js
@@ -313,7 +313,7 @@ export default {
 	},
 };
 
-function LayoutTypeSwitcher( { key, onChange } ) {
+function LayoutTypeSwitcher( { type, onChange } ) {
 	return (
 		<ToggleGroupControl
 			__next40pxDefaultSize
@@ -322,16 +322,16 @@ function LayoutTypeSwitcher( { key, onChange } ) {
 			__nextHasNoMarginBottom
 			hideLabelFromVision
 			isAdaptiveWidth
+			value={ type }
+			onChange={ onChange }
 		>
 			{ getLayoutTypes().map( ( { name, label } ) => {
 				return (
 					<ToggleGroupControlOption
+						key={ name }
 						value={ name }
-						label={ name }
-						onClick={ () => onChange( name ) }
-					>
-						{ label }
-					</ToggleGroupControlOption>
+						label={ label }
+					/>
 				);
 			} ) }
 		</ToggleGroupControl>
CleanShot.2024-09-26.at.09.03.34.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mirka Thank you for the feedback. I'm still green when it comes to the components. I made the changes you suggested. Please take a look when you get a chance. 55ec469

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, they can be complicated 😆

<ToggleGroupControl
__next40pxDefaultSize
isBlock
label={ __( 'Layout Type Select' ) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a simpler label would be more in line with all the other labels, what do you think?

Suggested change
label={ __( 'Layout Type Select' ) }
label={ __( 'Layout type' ) }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much cleaner and to the point. I made this change along with those you mentioned above.

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for the follow-up!

@mirka mirka enabled auto-merge (squash) September 26, 2024 23:15
@mirka mirka changed the title updates LayoutTypeSwitcher to useToggleGroupControl updates LayoutTypeSwitcher to use ToggleGroupControl Sep 26, 2024
@noisysocks noisysocks merged commit 65e7db0 into WordPress:trunk Sep 30, 2024
63 checks passed
@github-actions github-actions bot added this to the Gutenberg 19.4 milestone Sep 30, 2024
@github-actions github-actions bot removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Sep 30, 2024
gutenbergplugin pushed a commit that referenced this pull request Sep 30, 2024
* updates LayoutTypeSwitcher to useToggleGroupControl

* updates label and corrects LayoutTypeSwitcher component misconfiguration

Co-authored-by: spadeshoe <spdft@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
@github-actions github-actions bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Sep 30, 2024
Copy link

I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: 2233538

huubl pushed a commit to huubl/gutenberg that referenced this pull request Oct 2, 2024
* updates LayoutTypeSwitcher to useToggleGroupControl

* updates label and corrects LayoutTypeSwitcher component misconfiguration

Co-authored-by: spadeshoe <spdft@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
huubl added a commit to huubl/gutenberg that referenced this pull request Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants