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

Button component: Fix RTL alignment when containing icon and text #44787

Merged
merged 2 commits into from
Oct 20, 2022

Conversation

jornp
Copy link
Contributor

@jornp jornp commented Oct 7, 2022

What?

This fixes the RTL alignment inside the Button component for buttons with both an icon and text.

Why?

The .components-button.has-icon.has-text style had a justify-content: left, because of which the button contents were always left-aligned, even in RTL languages.

This effect normally isn't visible because the buttons aren't wide enough. But it became apparent in Calypso: when opening the block editor's sidebar, the "View Posts" button is actually a wider one:

image

For this button, the problem with the alignment for RTL languages is visible:

image

How?

This PR changes the justify-content from left to start, which works for both LTR and RTL languages.

Testing Instructions

  1. Replace the content of any block's edit.js with the following — some extra width has been added to the button to be able to see the effect of the alignment:
/**
 * WordPress dependencies
 */
import { useBlockProps } from '@wordpress/block-editor';
import { Button } from '@wordpress/components';
import { plusCircle } from '@wordpress/icons';

export default function CodeEdit( { attributes, setAttributes, onRemove } ) {
	const blockProps = useBlockProps();
	return (
		<div { ...blockProps }>
			<Button variant="primary" icon={ plusCircle } style={{ width: 200 }}>
				Hello
			</Button>
		</div>
	);
}
  1. Switch to an RTL language, edit a post, add the block you replaced, and confirm that the button contents are now right-aligned.
  2. Switch to an LTR language, edit a post, add the block you replaced, and confirm that the button contents are still left-aligned.

Screenshots

RTL before & after:
image
image

LTR before & after (should be unchanged):
image
image

@jornp jornp requested a review from ajitbohra as a code owner October 7, 2022 19:38
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Oct 7, 2022
@github-actions
Copy link

github-actions bot commented Oct 7, 2022

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @jornp! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

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

@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components labels Oct 18, 2022
@ciampo ciampo added this to In progress (owned) ⏳ in WordPress Components via automation Oct 18, 2022
Copy link
Contributor

@chad1008 chad1008 left a comment

Choose a reason for hiding this comment

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

The change looks good, and it's testing well for me. 🎉 Thanks for the fix @jornp!

Copy link
Contributor

@chad1008 chad1008 left a comment

Choose a reason for hiding this comment

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

Actually, I almost forgot... @jornp, can you add a quick CHANGELOG entry before merging? 🙂

@jornp jornp force-pushed the fix/button-component-rtl-alignment branch from 285c398 to 8e3f32d Compare October 20, 2022 11:30
@@ -315,7 +315,7 @@
}

&.has-text {
justify-content: left;
justify-content: start;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just leaving this link here for more details and for anyone looking back at this PR:

What's the difference between the alignment values of start, flex-start, and self-start?

@jornp
Copy link
Contributor Author

jornp commented Oct 20, 2022

Thanks for the review, @chad1008! I've added a changelog entry. 🙂

Since this is my first contribution here, I'm not authorized to merge the PR. Would you be able to merge it, or is there a way for me to do it? Thanks!

@ciampo
Copy link
Contributor

ciampo commented Oct 20, 2022

That's correct, you won't be able to merge it! I can do that for you :)

(React Native e2e test failures don't seem related to the changes in this PR)

@ciampo ciampo merged commit bd10c19 into WordPress:trunk Oct 20, 2022
WordPress Components automation moved this from In progress (owned) ⏳ to Done 🎉 Oct 20, 2022
@github-actions
Copy link

Congratulations on your first merged pull request, @jornp! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 14.5 milestone Oct 20, 2022
@jornp jornp deleted the fix/button-component-rtl-alignment branch October 20, 2022 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
3 participants