-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
bug(tabs): fix inifinite tab loop #4639 #6663
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5b510de
bug(tabs): fix inifinite tab loop #4639
amcdnl bd0adee
chore(nit): fix tslint issues
amcdnl 8c7c909
chore(nit): replace timeout w/ zone run
amcdnl 68cd5d5
chore(nit): fix comments
amcdnl 04153de
chore(nit): tweaks per feedback
amcdnl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,6 @@ import { | |
ViewEncapsulation, | ||
} from '@angular/core'; | ||
import {coerceBooleanProperty} from '@angular/cdk/coercion'; | ||
import {map} from '@angular/cdk/rxjs'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import {Subscription} from 'rxjs/Subscription'; | ||
import {MdTab} from './tab'; | ||
import {merge} from 'rxjs/observable/merge'; | ||
|
@@ -131,9 +129,7 @@ export class MdTabGroup extends _MdTabGroupMixinBase implements AfterContentInit | |
private _backgroundColor: ThemePalette; | ||
|
||
/** Output to enable support for two-way binding on `[(selectedIndex)]` */ | ||
@Output() get selectedIndexChange(): Observable<number> { | ||
return map.call(this.selectChange, event => event.index); | ||
} | ||
@Output() selectedIndexChange: EventEmitter<number> = new EventEmitter(); | ||
|
||
/** Event emitted when focus has changed within a tab group. */ | ||
@Output() focusChange: EventEmitter<MdTabChangeEvent> = new EventEmitter<MdTabChangeEvent>(); | ||
|
@@ -157,16 +153,20 @@ export class MdTabGroup extends _MdTabGroupMixinBase implements AfterContentInit | |
* a new selected tab should transition in (from the left or right). | ||
*/ | ||
ngAfterContentChecked(): void { | ||
// Clamp the next selected index to the bounds of 0 and the tabs length. Note the `|| 0`, which | ||
// ensures that values like NaN can't get through and which would otherwise throw the | ||
// component into an infinite loop (since Math.max(NaN, 0) === NaN). | ||
// Clamp the next selected index to the boundsof 0 and the tabs length. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did the comment change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I had changed it and had to reformat it to fix length but then backed that out and didn't undo the reformat. Sorry. |
||
// Note the `|| 0`, which ensures that values like NaN can't get through | ||
// and which would otherwise throw the component into an infinite loop | ||
// (since Math.max(NaN, 0) === NaN). | ||
let indexToSelect = this._indexToSelect = | ||
Math.min(this._tabs.length - 1, Math.max(this._indexToSelect || 0, 0)); | ||
|
||
// If there is a change in selected index, emit a change event. Should not trigger if | ||
// the selected index has not yet been initialized. | ||
if (this._selectedIndex != indexToSelect && this._selectedIndex != null) { | ||
this.selectChange.emit(this._createChangeEvent(indexToSelect)); | ||
// Emitting this value after change detection has run | ||
// since the checked content may contain this variable' | ||
Promise.resolve().then(() => this.selectedIndexChange.emit(indexToSelect)); | ||
} | ||
|
||
// Setup the position for each tab and optionally setup an origin on the next selected tab. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is this
setTimeout
instead of usingfixture.whenStable()
?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 used
setTimeout
because thats what his demo used.