Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 0d9133d

Browse files
authored
fix(top-app-bar): Set scrollHandler from initFoundation (#1786)
fix #1785
1 parent 08f736a commit 0d9133d

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

packages/top-app-bar/top-app-bar.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
MdcTopAppBarActionItem,
2525
MdcTopAppBarNavigationIcon,
2626
} from './top-app-bar.directives';
27+
28+
import { cssClasses } from '@material/top-app-bar/constants';
2729
import {
2830
MDCTopAppBarFoundation,
2931
MDCShortTopAppBarFoundation,
@@ -105,7 +107,8 @@ export class MdcTopAppBar implements AfterContentInit, AfterViewInit, OnDestroy
105107
get fixedAdjustElement(): HTMLElement | null { return this._fixedAdjustElement; }
106108
set fixedAdjustElement(element: HTMLElement | null) {
107109
if (this._fixedAdjustElement !== element) {
108-
this.setFixedAdjustElement(element);
110+
this._fixedAdjustElement = element;
111+
this._initTopAppBar();
109112
}
110113
}
111114
private _fixedAdjustElement: HTMLElement | null = null;
@@ -134,7 +137,7 @@ export class MdcTopAppBar implements AfterContentInit, AfterViewInit, OnDestroy
134137
hasClass: (className: string) => this._getHostElement().classList.contains(className),
135138
addClass: (className: string) => this._getHostElement().classList.add(className),
136139
removeClass: (className: string) => {
137-
if (className === 'mdc-top-app-bar--short-collapsed' && this.shortCollapsed) {
140+
if (className === cssClasses.SHORT_COLLAPSED_CLASS && this.shortCollapsed) {
138141
return;
139142
}
140143
this._getHostElement().classList.remove(className);
@@ -176,11 +179,10 @@ export class MdcTopAppBar implements AfterContentInit, AfterViewInit, OnDestroy
176179
public elementRef: ElementRef) { }
177180

178181
ngAfterContentInit(): void {
179-
this.actions.changes.pipe(startWith(null),
180-
takeUntil(this._destroyed))
182+
this.actions.changes.pipe(startWith(null), takeUntil(this._destroyed))
181183
.subscribe(() => {
182184
if (this.short && this.actions.length) {
183-
this._getHostElement().classList.toggle('mdc-top-app-bar--short-has-action-item');
185+
this._getHostElement().classList.toggle(cssClasses.SHORT_HAS_ACTION_ITEM_CLASS);
184186
}
185187
});
186188
}
@@ -201,11 +203,6 @@ export class MdcTopAppBar implements AfterContentInit, AfterViewInit, OnDestroy
201203
this._destroyFoundation();
202204
}
203205

204-
setFixedAdjustElement(element: HTMLElement | null): void {
205-
this._fixedAdjustElement = element;
206-
this._initTopAppBar();
207-
}
208-
209206
/** Sets the top app bar to fixed or not. */
210207
setFixed(fixed: boolean, isUserInput: boolean = true): void {
211208
this._fixed = toBoolean(fixed);
@@ -276,7 +273,7 @@ export class MdcTopAppBar implements AfterContentInit, AfterViewInit, OnDestroy
276273
}
277274

278275
isCollapsed(): boolean {
279-
return this._getHostElement().classList.contains('mdc-top-app-bar--short-collapsed');
276+
return this._getHostElement().classList.contains(cssClasses.SHORT_COLLAPSED_CLASS);
280277
}
281278

282279
private _initFoundation(): void {
@@ -298,36 +295,36 @@ export class MdcTopAppBar implements AfterContentInit, AfterViewInit, OnDestroy
298295
this._isFoundationInit = true;
299296

300297
this._initTopAppBar();
301-
298+
this._initScrollHandler();
302299
this._changeDetectorRef.markForCheck();
303300
}, 20);
304301
}
305302

306303
private _resetFixedShort(): void {
307-
this._getHostElement().classList.remove('mdc-top-app-bar--short-has-action-item');
308-
this._getHostElement().classList.remove('mdc-top-app-bar--short-collapsed');
309-
this._getHostElement().classList.remove('mdc-top-app-bar--fixed-scrolled');
304+
this._getHostElement().classList.remove(cssClasses.SHORT_HAS_ACTION_ITEM_CLASS);
305+
this._getHostElement().classList.remove(cssClasses.SHORT_COLLAPSED_CLASS);
306+
this._getHostElement().classList.remove(cssClasses.FIXED_SCROLLED_CLASS);
310307
}
311308

312309
private _initTopAppBar(): void {
313310
if (!this.fixed) {
314-
this._getHostElement().classList.remove('mdc-top-app-bar--fixed-scrolled');
311+
this._getHostElement().classList.remove(cssClasses.FIXED_SCROLLED_CLASS);
315312
}
316313

317314
if (this.fixed && this._getScrollOffset() > 0) {
318-
this._getHostElement().classList.add('mdc-top-app-bar--fixed-scrolled');
315+
this._getHostElement().classList.add(cssClasses.FIXED_SCROLLED_CLASS);
319316
}
320317

321318
if (!this.short) {
322-
this._getHostElement().classList.remove('mdc-top-app-bar--short-has-action-item');
323-
this._getHostElement().classList.remove('mdc-top-app-bar--short-collapsed');
319+
this._getHostElement().classList.remove(cssClasses.SHORT_HAS_ACTION_ITEM_CLASS);
320+
this._getHostElement().classList.remove(cssClasses.SHORT_COLLAPSED_CLASS);
324321
}
325322
if (this.short && this._getScrollOffset() > 0) {
326-
this._getHostElement().classList.add('mdc-top-app-bar--short-collapsed');
323+
this._getHostElement().classList.add(cssClasses.SHORT_COLLAPSED_CLASS);
327324
}
328325

329326
if (this.shortCollapsed) {
330-
this._getHostElement().classList.add('mdc-top-app-bar--short-collapsed');
327+
this._getHostElement().classList.add(cssClasses.SHORT_COLLAPSED_CLASS);
331328
}
332329

333330
if (this.fixedAdjustElement) {

packages/typings.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ declare module '@material/tab-scroller/index';
3838
declare module '@material/tab/index';
3939
declare module '@material/textfield/helper-text/index';
4040
declare module '@material/textfield/index';
41+
declare module '@material/top-app-bar/constants';
4142
declare module '@material/top-app-bar/index';

0 commit comments

Comments
 (0)