Skip to content

Commit

Permalink
Cover Block: Keep the inner contents in a physical direction even in …
Browse files Browse the repository at this point in the history
…RTL languages (#43663)

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

* Remove unnecessary change
  • Loading branch information
t-hamano authored Sep 7, 2022
1 parent 88f9456 commit 0122f4d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
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

0 comments on commit 0122f4d

Please sign in to comment.