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

Cover Block: Keep the inner contents in a physical direction even in RTL languages #43663

Merged
merged 2 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions packages/block-library/src/cover/edit/block-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
__experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl,
__experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl,
} from '@wordpress/block-editor';
import { __, isRTL } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -58,27 +58,15 @@ export default function CoverBlockControls( {
} );
};

// Flip value horizontally to match the physical direction indicated by
// AlignmentMatrixControl with the logical direction indicated by cover
// block in RTL languages.
const flipHorizontalPosition = ( ltrContentPosition ) => {
return isRTL()
? ltrContentPosition.replace( /left|right/, ( match ) =>
match === 'left' ? 'right' : 'left'
)
: ltrContentPosition;
};

return (
<>
<BlockControls group="block">
<BlockAlignmentMatrixControl
label={ __( 'Change content position' ) }
value={ flipHorizontalPosition( contentPosition ) }
value={ contentPosition }
onChange={ ( nextPosition ) =>
setAttributes( {
contentPosition:
flipHorizontalPosition( nextPosition ),
contentPosition: nextPosition,
} )
}
isDisabled={ ! hasInnerBlocks }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/cover/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
padding: 1em;
// This block has customizable padding, border-box makes that more predictable.
box-sizing: border-box;
// Keep the flex layout direction to the physical direction (LTR) in RTL languages.
/*rtl:raw: direction: ltr; */

/**
* Set a default background color for has-background-dim _unless_ it includes another
Expand Down Expand Up @@ -105,6 +107,8 @@
width: 100%;
z-index: z-index(".wp-block-cover__inner-container");
color: $white;
// Reset the fixed LTR direction at the root of the block in RTL languages.
/*rtl:raw: direction: rtl; */
}

&.is-light {
Expand Down