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

AlignmentMatrixControl: keep the physical direction in RTL languages #43126

Merged
merged 9 commits into from
Aug 26, 2022
4 changes: 2 additions & 2 deletions packages/components/src/alignment-matrix-control/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { VisuallyHidden } from '../visually-hidden';
/**
* Internal dependencies
*/
import { ALIGNMENT_LABEL } from './utils';
import { getAlignmentLabel } from './utils';
import {
Cell as CellView,
Point,
} from './styles/alignment-matrix-control-styles';

export default function Cell( { isActive = false, value, ...props } ) {
const tooltipText = ALIGNMENT_LABEL[ value ];
const tooltipText = getAlignmentLabel( value );

return (
<Tooltip text={ tooltipText }>
Expand Down
19 changes: 18 additions & 1 deletion packages/components/src/alignment-matrix-control/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, isRTL } from '@wordpress/i18n';

export const GRID = [
[ 'top left', 'top center', 'top right' ],
Expand Down Expand Up @@ -65,3 +65,20 @@ export function getAlignmentIndex( alignment = 'center' ) {

return index > -1 ? index : undefined;
}

/**
* Retrieves the alignment label from a value.
*
* @param {string} alignment Value to check.
*
* @return {number} The label of a matching alignment.
*/
export function getAlignmentLabel( alignment = 'center' ) {
// Swap left and right in RTL languages.
const newAlignment = isRTL()
? alignment.replace( /left|right/, ( match ) =>
match === 'left' ? 'right' : 'left'
)
: alignment;
return ALIGNMENT_LABEL[ newAlignment ] || undefined;
}