Skip to content

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

Merged
merged 5 commits into from
Jun 29, 2018
Merged

fix(GlobalPositionStrategy): justifyContent center ignored when direction is RTL #11877

merged 5 commits into from
Jun 29, 2018

Conversation

leibale
Copy link
Contributor

@leibale leibale commented Jun 21, 2018

In d3a3136 @crisbeto makes justify-content invert when the direction is RTL, but he forgot to to it only if the justify-content is flex-start or flex-end.

…tion is RTL

In d3a3136 @crisbeto makes `justify-content` invert when the direction is RTL, but he forgot to to it only if the `justify-content` is `flex-start` or `flex-end`.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 21, 2018
@@ -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-')) {
Copy link
Member

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'.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Leibale Eidelman added 2 commits June 21, 2018 19:04
clean some code - with @crisbeto
@crisbeto
Copy link
Member

@leibale looks like one of tests is failing.

@leibale
Copy link
Contributor Author

leibale commented Jun 21, 2018

@crisbeto this is because of the change I suggested in the commit comments and you accepted..
What should I do instead? Revert the code to the first commit?

@crisbeto
Copy link
Member

Can you add another else if (this._justifyContent === 'center') in there?

@leibale
Copy link
Contributor Author

leibale commented Jun 24, 2018

@crisbeto this makes other tests to fail (like "GlobalPositonStrategy should overwrite previously applied positioning"), I'm reverting the code to baf4fec.

@crisbeto
Copy link
Member

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;
    }

Copy link
Member

@crisbeto crisbeto left a 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';
Copy link
Member

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.

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jun 24, 2018
@josephperrott
Copy link
Member

josephperrott commented Jun 28, 2018

Fixes #11912

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants