From 1ce4fe7ed29b38875b7852c63c7d8281ba6f8b94 Mon Sep 17 00:00:00 2001 From: Enlcxx Date: Fri, 7 Jun 2019 20:26:59 -0400 Subject: [PATCH] fix(tabs): `selectedIndexChange` do not emit first value --- .../tabs-with-lazy-loading.component.ts | 8 ++++---- src/lib/tabs/tabs.ts | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/docs/layout/tabs-demo/tabs-with-lazy-loading/tabs-with-lazy-loading.component.ts b/src/app/docs/layout/tabs-demo/tabs-with-lazy-loading/tabs-with-lazy-loading.component.ts index 506bb6ff6..b894b6104 100644 --- a/src/app/docs/layout/tabs-demo/tabs-with-lazy-loading/tabs-with-lazy-loading.component.ts +++ b/src/app/docs/layout/tabs-demo/tabs-with-lazy-loading/tabs-with-lazy-loading.component.ts @@ -16,6 +16,10 @@ export class TabsWithLazyLoadingComponent { readonly classes = this.theme.addStyleSheet(styles); tabLoadTimes: Date[] = []; + constructor( + private theme: LyTheme2 + ) { } + getTime(index: number) { if (!this.tabLoadTimes[index]) { this.tabLoadTimes[index] = new Date(); @@ -24,8 +28,4 @@ export class TabsWithLazyLoadingComponent { return this.tabLoadTimes[index]; } - constructor( - private theme: LyTheme2 - ) { } - } diff --git a/src/lib/tabs/tabs.ts b/src/lib/tabs/tabs.ts index c6ee3b09f..72915c552 100644 --- a/src/lib/tabs/tabs.ts +++ b/src/lib/tabs/tabs.ts @@ -190,7 +190,7 @@ mixinBg( export class LyTabs extends LyTabsMixinBase implements OnChanges, OnInit, AfterViewInit, AfterContentInit, OnDestroy { /** @docs-private */ readonly classes = this.theme.addStyleSheet(STYLES); - _selectedIndex = 0; + _selectedIndex: number; _selectedBeforeIndex: number; _selectedTab: LyTab | null; _selectedBeforeTab: LyTab; @@ -395,6 +395,9 @@ export class LyTabs extends LyTabsMixinBase implements OnChanges, OnInit, AfterV } ngOnInit() { + if (this.selectedIndex == null) { + this.selectedIndex = 0; + } this.renderer.addClass(this.el.nativeElement, this.classes.root); const tabsIndicatorEl = this.tabsIndicator.nativeElement; this.renderer.addClass(tabsIndicatorEl, this.classes.tabsIndicator);