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

Commit 5d2bcbf

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(fabToolbar): fail gracefully if no icon used in trigger
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. Closes #3601.
1 parent 84c5bff commit 5d2bcbf

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/components/fabToolbar/fabToolbar.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
'use strict';
33

44
angular
5+
// Declare our module
56
.module('material.components.fabToolbar', [
67
'material.core',
78
'material.components.fabTrigger',
89
'material.components.fabActions'
910
])
11+
12+
// Register our directive
1013
.directive('mdFabToolbar', MdFabToolbarDirective)
11-
.animation('.md-fab-toolbar', MdFabToolbarAnimation);
14+
15+
// Register our custom animations
16+
.animation('.md-fab-toolbar', MdFabToolbarAnimation)
17+
18+
// Register a service for the animation so that we can easily inject it into unit tests
19+
.service('mdFabToolbarAnimation', MdFabToolbarAnimation);
1220

1321
/**
1422
* @ngdoc directive
@@ -157,7 +165,7 @@
157165

158166
// Set the next close animation to have the proper delays
159167
backgroundElement.style.transitionDelay = '0ms';
160-
iconElement.style.transitionDelay = '.3s';
168+
iconElement && (iconElement.style.transitionDelay = '.3s');
161169

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

184192
// Set the next open animation to have the proper delays
185193
backgroundElement.style.transitionDelay = '200ms';
186-
iconElement.style.transitionDelay = '0ms';
194+
iconElement && (iconElement.style.transitionDelay = '0ms');
187195

188196
// Apply a transition delay to actions
189197
angular.forEach(actions, function(action, index) {
@@ -196,10 +204,12 @@
196204
return {
197205
addClass: function(element, className, done) {
198206
runAnimation(element, className, done);
207+
done();
199208
},
200209

201210
removeClass: function(element, className, done) {
202211
runAnimation(element, className, done);
212+
done();
203213
}
204214
}
205215
}

src/components/fabToolbar/fabToolbar.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,22 @@ describe('<md-fab-toolbar> directive', function() {
6262
expect(controller.isOpen).toBe(false);
6363
}));
6464

65+
it('properly finishes the animation', inject(function(mdFabToolbarAnimation) {
66+
compileAndLink(
67+
'<md-fab-toolbar md-open="isOpen">' +
68+
' <md-fab-trigger><button></button></md-fab-trigger>' +
69+
' <md-fab-actions><button></button></md-fab-actions>' +
70+
'</md-fab-toolbar>'
71+
);
72+
73+
var addDone = jasmine.createSpy('addDone');
74+
var removeDone = jasmine.createSpy('removeDone');
75+
76+
mdFabToolbarAnimation.addClass(element, 'md-is-open', addDone);
77+
expect(addDone).toHaveBeenCalled();
78+
79+
mdFabToolbarAnimation.removeClass(element, 'md-is-open', removeDone);
80+
expect(removeDone).toHaveBeenCalled();
81+
}));
82+
6583
});

0 commit comments

Comments
 (0)