Skip to content

Commit f96ffeb

Browse files
amcdnlmmalerba
authored andcommitted
bug(tabs): fix arrows not showing on reszize #6303 (#6304)
* bug(tabs): fix arrows not showing on reszize #6303 * chore(*): update to use host vs hostliener * bug(tabs): address feedback in pr * bug(tabs): address PR feedback
1 parent cea4d9f commit f96ffeb

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/lib/tabs/tab-header.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {async, ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/testing';
1+
import {
2+
async, ComponentFixture, TestBed, fakeAsync, tick, discardPeriodicTasks
3+
} from '@angular/core/testing';
24
import {Component, ViewChild, ViewContainerRef} from '@angular/core';
35
import {Direction, Directionality} from '../core/bidi/index';
46
import {MdTabHeader} from './tab-header';
@@ -261,6 +263,22 @@ describe('MdTabHeader', () => {
261263
fixture.detectChanges();
262264

263265
expect(inkBar.alignToElement).toHaveBeenCalled();
266+
discardPeriodicTasks();
267+
}));
268+
269+
it('should update arrows when the window is resized', fakeAsync(() => {
270+
fixture = TestBed.createComponent(SimpleTabHeaderApp);
271+
272+
const header = fixture.componentInstance.mdTabHeader;
273+
274+
spyOn(header, '_checkPaginationEnabled');
275+
276+
dispatchFakeEvent(window, 'resize');
277+
tick(10);
278+
fixture.detectChanges();
279+
280+
expect(header._checkPaginationEnabled).toHaveBeenCalled();
281+
discardPeriodicTasks();
264282
}));
265283

266284
});

src/lib/tabs/tab-header.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
NgZone,
2424
Renderer2,
2525
ChangeDetectionStrategy,
26-
ChangeDetectorRef,
26+
ChangeDetectorRef
2727
} from '@angular/core';
2828
import {
2929
RIGHT_ARROW,
@@ -40,7 +40,8 @@ import {of as observableOf} from 'rxjs/observable/of';
4040
import {merge} from 'rxjs/observable/merge';
4141
import {fromEvent} from 'rxjs/observable/fromEvent';
4242
import {CanDisableRipple, mixinDisableRipple} from '../core/common-behaviors/disable-ripple';
43-
43+
import {RxChain, debounceTime} from '@angular/cdk/rxjs';
44+
import {Platform} from '@angular/cdk/platform';
4445

4546
/**
4647
* The directions that scrolling can go in when the header's tabs exceed the header width. 'After'
@@ -121,6 +122,9 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
121122

122123
private _selectedIndex: number = 0;
123124

125+
/** subscription for the window resize handler */
126+
private _resizeSubscription: Subscription | null;
127+
124128
/** The index of the active tab. */
125129
@Input()
126130
get selectedIndex(): number { return this._selectedIndex; }
@@ -141,8 +145,16 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
141145
private _ngZone: NgZone,
142146
private _renderer: Renderer2,
143147
private _changeDetectorRef: ChangeDetectorRef,
144-
@Optional() private _dir: Directionality) {
148+
@Optional() private _dir: Directionality,
149+
platform: Platform) {
145150
super();
151+
152+
if (platform.isBrowser) {
153+
// TODO: Add library level window listener https://goo.gl/y25X5M
154+
this._resizeSubscription = RxChain.from(fromEvent(window, 'resize'))
155+
.call(debounceTime, 150)
156+
.subscribe(() => this._checkPaginationEnabled());
157+
}
146158
}
147159

148160
ngAfterContentChecked(): void {
@@ -208,6 +220,11 @@ export class MdTabHeader extends _MdTabHeaderMixinBase
208220
this._realignInkBar.unsubscribe();
209221
this._realignInkBar = null;
210222
}
223+
224+
if (this._resizeSubscription) {
225+
this._resizeSubscription.unsubscribe();
226+
this._resizeSubscription = null;
227+
}
211228
}
212229

213230
/**

0 commit comments

Comments
 (0)