-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(GlobalPositionStrategy): justifyContent center ignored when direction is RTL #11877
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
fix(GlobalPositionStrategy): justifyContent center ignored when direction is RTL #11877
Conversation
@@ -169,7 +169,7 @@ export class GlobalPositionStrategy implements PositionStrategy { | |||
|
|||
if (config.width === '100%') { | |||
parentStyles.justifyContent = 'flex-start'; | |||
} else if (this._overlayRef.getConfig().direction === 'rtl') { | |||
} else if (this._overlayRef.getConfig().direction === 'rtl' && this._justifyContent.startsWith('flex-')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of context, it's hard to see the reasoning behind this check. I would switch it so the check is this._overlayRef.getConfig().direction === 'rtl' && this._justifyContent !== 'center'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Don't you want space-between
(as an example) to work too?
You can see here the options for justify-content
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the overlay wrapper can only have one overlay panel at a time, I wouldn't worry too much about any of the other flex values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about another solution for that:
if (config.width === '100%') {
parentStyles.justifyContent = 'flex-start';
} else if (this._overlayRef.getConfig().direction === 'rtl') {
// In RTL the browser will invert `flex-start` and `flex-end` automatically, but we
// don't want that because our positioning is explicitly `left` and `right`, hence
// why we do another inversion to ensure that the overlay stays in the same position.
// TODO: reconsider this if we add `start` and `end` methods.
if (this._justifyContent === 'flex-start') {
parentStyles.justifyContent = 'flex-end';
} else if (this._justifyContent === 'flex-end') {
parentStyles.justifyContent = 'flex-start';
}
}
parentStyles.justifyContent = parentStyles.justifyContent || this._justifyContent;
Or maybe change the last line to:
if (config.width === '100%') {
parentStyles.justifyContent = 'flex-start';
} else if (this._overlayRef.getConfig().direction === 'rtl') {
// In RTL the browser will invert `flex-start` and `flex-end` automatically, but we
// don't want that because our positioning is explicitly `left` and `right`, hence
// why we do another inversion to ensure that the overlay stays in the same position.
// TODO: reconsider this if we add `start` and `end` methods.
if (this._justifyContent === 'flex-start') {
parentStyles.justifyContent = 'flex-end';
} else if (this._justifyContent === 'flex-end') {
parentStyles.justifyContent = 'flex-start';
}
}
if (!parentStyles.justifyContent) {
parentStyles.justifyContent = this._justifyContent;
}
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter option looks good as well.
fix lint
clean some code - with @crisbeto
@leibale looks like one of tests is failing. |
@crisbeto this is because of the change I suggested in the commit comments and you accepted.. |
Can you add another |
Here's what I meant. This passes all tests, including the one introduced in this PR: if (config.width === '100%') {
parentStyles.justifyContent = 'flex-start';
} else if (this._justifyContent === 'center') {
parentStyles.justifyContent = 'center';
} else if (this._overlayRef.getConfig().direction === 'rtl') {
// In RTL the browser will invert `flex-start` and `flex-end` automatically, but we
// don't want that because our positioning is explicitly `left` and `right`, hence
// why we do another inversion to ensure that the overlay stays in the same position.
// TODO: reconsider this if we add `start` and `end` methods.
if (this._justifyContent === 'flex-start') {
parentStyles.justifyContent = 'flex-end';
} else if (this._justifyContent === 'flex-end') {
parentStyles.justifyContent = 'flex-start';
}
} else {
parentStyles.justifyContent = this._justifyContent;
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -169,6 +169,8 @@ export class GlobalPositionStrategy implements PositionStrategy { | |||
|
|||
if (config.width === '100%') { | |||
parentStyles.justifyContent = 'flex-start'; | |||
} else if (this._justifyContent === 'center') { | |||
parentStyles.justifyContent = 'center'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the indentation here is too much.
Fixes #11912 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
In d3a3136 @crisbeto makes
justify-content
invert when the direction is RTL, but he forgot to to it only if thejustify-content
isflex-start
orflex-end
.