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

fix(toolbar): fix the toolbar not shrinking on load #8543

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/toolbar/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate) {
contentElement.on('scroll', debouncedContentScroll);
contentElement.attr('scroll-shrink', 'true');

$$rAF(updateToolbarHeight);
$mdUtil.nextTick(updateToolbarHeight, false);

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

$$rAF(updateToolbarHeight);
}
updateToolbarHeight();
};
}

/**
Expand Down
15 changes: 5 additions & 10 deletions src/components/toolbar/toolbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('<md-toolbar>', function() {
$timeout = _$timeout_;
}));

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

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

$rootScope.$apply();
$rootScope.$broadcast('$mdContentLoaded', contentEl);
$$rAF.flush();
$timeout.flush();


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

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

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

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

// Flushing to get the actual height of toolbar
$$rAF.flush();

//
// Initial tests
//
Expand Down Expand Up @@ -171,7 +166,7 @@ describe('<md-toolbar>', function() {
document.body.removeChild(element[0]);
}));

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

// Flushing to get the actual height of toolbar
$$rAF.flush();
$timeout.flush();

//
// Initial tests
Expand Down