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

fix(tabs): reposition tab body on direction change #12229

Conversation

devversion
Copy link
Member

  • Currently, if someone switches to RTL after the tabs have been rendered, the hidden tabs will not update their position. Meaning that the tabs will animate from the wrong side if a new tab is selected.

Note: I noticed that the Tab group with dynamically changing tabs example is not working properly anymore (this already happened before my changes; see docs). Will look into it.

@devversion devversion added i18n This issue is related to internationalization target: patch This PR is targeted for the next patch release labels Jul 16, 2018
@devversion devversion requested a review from andrewseguin as a code owner July 16, 2018 13:02
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 16, 2018
* Currently, if someone switches to RTL after the tabs have been rendered, the hidden tabs will not update their position. Meaning that the tabs will animate from the wrong side if a new tab is selected.
@devversion devversion force-pushed the fix/tabs-reposition-tabs-body-dir-change branch from 1e1285b to fa3eae6 Compare July 16, 2018 14:09
this._origin = 'right';
constructor(private _elementRef: ElementRef,
@Optional() private _dir: Directionality,
// TODO(paul): make the changeDetectorRef required when doing breaking changes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark this with a @deletion-target, otherwise we'll miss it when doing breaking changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about that because deletion-target kind of implies that we are going to delete that parameter.


if ((dir == 'ltr' && this.origin <= 0) || (dir == 'rtl' && this.origin > 0)) {
return 'left-origin-center';
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else here is redundant, you can just return at the bottom.

Copy link
Member Author

@devversion devversion Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just took that logic from above, but makes sense. Will improve it.

@@ -202,4 +210,29 @@ export class MatTabBody implements OnInit {
position == 'left-origin-center' ||
position == 'right-origin-center';
}

/** Computes the position state that will be used for the tab-body animation trigger. */
private _computePositionAnimationState(dir: Direction = this._getLayoutDirection()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell you're never passing a dir to the calls of this method. Consider moving it into a variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dir is being passed from the subscribe in the constructor.

private _positionIndex: number;

/** Subscription to the directionality change observable. */
private _dirChangeSubscription: Subscription = Subscription.EMPTY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Subscription type here is inferred already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

changeDetectorRef?: ChangeDetectorRef) {

if (this._dir && changeDetectorRef) {
this._dir.change.subscribe(dir => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this assign to the _dirChangeSubscription? Also if you're doing this in the constructor, you don't have to initialize it to Subscription.EMPTY.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Missed that. Since dir is not always present, we need to either truthy check for the subscription or just use Subscription.EMPTY.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@devversion devversion force-pushed the fix/tabs-reposition-tabs-body-dir-change branch from 99635e5 to 8a7a9c7 Compare July 16, 2018 16:23
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

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jul 16, 2018
@josephperrott josephperrott merged commit 49ec9ca into angular:master Jul 18, 2018
devversion added a commit to devversion/material2 that referenced this pull request Aug 6, 2018
* Due to angular#12229, the selected tab of a tab-group will incorrectly animate after initialization. This happens because the `MatTab` component by default assigns the `origin` to `null`. Right now the check does only handle `undefined` properly.

Fixes angular#12455
devversion added a commit to devversion/material2 that referenced this pull request Aug 6, 2018
* Due to angular#12229, the selected tab of a tab-group will incorrectly animate after initialization. This happens because the `MatTab` component by default assigns the `origin` to `null`. Right now the check does only handle `undefined` properly.

Fixes angular#12455
@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 i18n This issue is related to internationalization 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