Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 72ed02f

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(toolbar): fix the toolbar not shrinking on load
The function that updates the toolbar height was firing too early, which caused the shrinking functionality not to work until 5sec after the last scroll event. This commit fixes it by waiting until the first digest before initializing the toolbar height. Fixes #8258, #8221. Closes #8543
1 parent 71529d7 commit 72ed02f

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/components/toolbar/toolbar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate) {
193193
contentElement.on('scroll', debouncedContentScroll);
194194
contentElement.attr('scroll-shrink', 'true');
195195

196-
$$rAF(updateToolbarHeight);
196+
$mdUtil.nextTick(updateToolbarHeight, false);
197197

198198
return function disableScrollShrink() {
199199
contentElement.off('scroll', debouncedContentScroll);
200200
contentElement.attr('scroll-shrink', 'false');
201201

202-
$$rAF(updateToolbarHeight);
203-
}
202+
updateToolbarHeight();
203+
};
204204
}
205205

206206
/**

src/components/toolbar/toolbar.spec.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('<md-toolbar>', function() {
1313
$timeout = _$timeout_;
1414
}));
1515

16-
it('with scrollShrink, it should shrink scrollbar when going to bottom', inject(function($compile, $rootScope, $mdConstant, mdToolbarDirective, $$rAF) {
16+
it('with scrollShrink, it should shrink scrollbar when going to bottom', inject(function($compile, $rootScope, $mdConstant, mdToolbarDirective) {
1717

1818
var parent = angular.element('<div>');
1919
var toolbar = angular.element('<md-toolbar>');
@@ -55,7 +55,7 @@ describe('<md-toolbar>', function() {
5555

5656
$rootScope.$apply();
5757
$rootScope.$broadcast('$mdContentLoaded', contentEl);
58-
$$rAF.flush();
58+
$timeout.flush();
5959

6060

6161
//Expect everything to be in its proper initial state.
@@ -69,7 +69,6 @@ describe('<md-toolbar>', function() {
6969
type: 'scroll',
7070
target: {scrollTop: 500}
7171
});
72-
$$rAF.flush();
7372

7473
expect(toolbarCss[$mdConstant.CSS.TRANSFORM]).toEqual('translate3d(0,-100px,0)');
7574
expect(contentCss[$mdConstant.CSS.TRANSFORM]).toEqual('translate3d(0,0px,0)');
@@ -79,7 +78,6 @@ describe('<md-toolbar>', function() {
7978
type: 'scroll',
8079
target: {scrollTop: 0}
8180
});
82-
$$rAF.flush();
8381

8482
expect(toolbarCss[$mdConstant.CSS.TRANSFORM]).toEqual('translate3d(0,0px,0)');
8583
expect(contentCss[$mdConstant.CSS.TRANSFORM]).toEqual('translate3d(0,100px,0)');
@@ -118,7 +116,7 @@ describe('<md-toolbar>', function() {
118116
expect(element.find('md-toolbar').length).toBe(0);
119117
}));
120118

121-
it('works with ng-show', inject(function($$rAF, $timeout) {
119+
it('works with ng-show', inject(function($timeout) {
122120
var template =
123121
'<div layout="column" style="height: 600px;">' +
124122
' <md-toolbar md-scroll-shrink="true" ng-show="shouldShowToolbar">test</md-toolbar>' +
@@ -129,9 +127,6 @@ describe('<md-toolbar>', function() {
129127
build(template);
130128
document.body.appendChild(element[0]);
131129

132-
// Flushing to get the actual height of toolbar
133-
$$rAF.flush();
134-
135130
//
136131
// Initial tests
137132
//
@@ -171,7 +166,7 @@ describe('<md-toolbar>', function() {
171166
document.body.removeChild(element[0]);
172167
}));
173168

174-
it('works with ng-hide', inject(function($$rAF, $timeout) {
169+
it('works with ng-hide', inject(function($timeout) {
175170
var template =
176171
'<div layout="column" style="height: 600px;">' +
177172
' <md-toolbar md-scroll-shrink="true" ng-hide="shouldNotShowToolbar">test</md-toolbar>' +
@@ -183,7 +178,7 @@ describe('<md-toolbar>', function() {
183178
document.body.appendChild(element[0]);
184179

185180
// Flushing to get the actual height of toolbar
186-
$$rAF.flush();
181+
$timeout.flush();
187182

188183
//
189184
// Initial tests

0 commit comments

Comments
 (0)