Skip to content

Commit 415c956

Browse files
leibalejosephperrott
authored andcommitted
fix(GlobalPositionStrategy): justifyContent center ignored when direction is RTL (#11877)
1 parent d5de711 commit 415c956

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/cdk/overlay/position/global-position-strategy.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,20 @@ describe('GlobalPositonStrategy', () => {
270270
expect(elementStyle.height).toBe('300px');
271271
});
272272

273+
it('should center the element in RTL', () => {
274+
attachOverlay({
275+
direction: 'rtl',
276+
positionStrategy: overlay.position()
277+
.global()
278+
.centerHorizontally()
279+
.centerVertically()
280+
});
281+
282+
const parentStyle = (overlayRef.overlayElement.parentNode as HTMLElement).style;
283+
expect(parentStyle.justifyContent).toBe('center');
284+
expect(parentStyle.alignItems).toBe('center');
285+
});
286+
273287
it('should invert `justify-content` when using `left` in RTL', () => {
274288
attachOverlay({
275289
positionStrategy: overlay.position().global().left('0'),

src/cdk/overlay/position/global-position-strategy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ export class GlobalPositionStrategy implements PositionStrategy {
169169

170170
if (config.width === '100%') {
171171
parentStyles.justifyContent = 'flex-start';
172+
} else if (this._justifyContent === 'center') {
173+
parentStyles.justifyContent = 'center';
172174
} else if (this._overlayRef.getConfig().direction === 'rtl') {
173175
// In RTL the browser will invert `flex-start` and `flex-end` automatically, but we
174176
// don't want that because our positioning is explicitly `left` and `right`, hence

0 commit comments

Comments
 (0)