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

Commit

Permalink
fix(fabToolbar): fail gracefully if no icon used in trigger
Browse files Browse the repository at this point in the history
the component previously assumed the user would have an icon
inside the trigger and was throwing an error upon animation
which caused the entire component to break

also fix a potential issue with the animation not properly
firing the `done()` callback when finished

closes #3223
  • Loading branch information
topherfangio committed Jul 6, 2015
1 parent a64291b commit d28febc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/fabToolbar/fabToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
'use strict';

angular
// Declare our module
.module('material.components.fabToolbar', [
'material.core',
'material.components.fabTrigger',
'material.components.fabActions'
])

// Register our directive
.directive('mdFabToolbar', MdFabToolbarDirective)
.animation('.md-fab-toolbar', MdFabToolbarAnimation);

// Register our custom animations
.animation('.md-fab-toolbar', MdFabToolbarAnimation)

// Register a service for the animation so that we can easily inject it into unit tests
.service('mdFabToolbarAnimation', MdFabToolbarAnimation);

/**
* @ngdoc directive
Expand Down Expand Up @@ -157,7 +165,7 @@

// Set the next close animation to have the proper delays
backgroundElement.style.transitionDelay = '0ms';
iconElement.style.transitionDelay = '.3s';
iconElement && (iconElement.style.transitionDelay = '.3s');

// Apply a transition delay to actions
angular.forEach(actions, function(action, index) {
Expand All @@ -183,7 +191,7 @@

// Set the next open animation to have the proper delays
backgroundElement.style.transitionDelay = '200ms';
iconElement.style.transitionDelay = '0ms';
iconElement && (iconElement.style.transitionDelay = '0ms');

// Apply a transition delay to actions
angular.forEach(actions, function(action, index) {
Expand All @@ -196,10 +204,12 @@
return {
addClass: function(element, className, done) {
runAnimation(element, className, done);
done();
},

removeClass: function(element, className, done) {
runAnimation(element, className, done);
done();
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/components/fabToolbar/fabToolbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,22 @@ describe('<md-fab-toolbar> directive', function() {
expect(controller.isOpen).toBe(false);
}));

it('properly finishes the animation', inject(function(mdFabToolbarAnimation) {
compileAndLink(
'<md-fab-toolbar md-open="isOpen">' +
' <md-fab-trigger><button></button></md-fab-trigger>' +
' <md-fab-actions><button></button></md-fab-actions>' +
'</md-fab-toolbar>'
);

var addDone = jasmine.createSpy('addDone');
var removeDone = jasmine.createSpy('removeDone');

mdFabToolbarAnimation.addClass(element, 'md-is-open', addDone);
expect(addDone).toHaveBeenCalled();

mdFabToolbarAnimation.removeClass(element, 'md-is-open', removeDone);
expect(removeDone).toHaveBeenCalled();
}));

});

0 comments on commit d28febc

Please sign in to comment.