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

Commit cfdd7cf

Browse files
topherfangiojelbourn
authored andcommitted
fix(speedDial): Fix intially open bug.
Due to an animation issue, the FAB Speed Dial started in an open state when using the `md-fling` animation. Fix by delaying the initial animation until after the component was fully rendered so that the animation's calculations were correct and adding some CSS to ensure the first animation fired instantly. Fixes #6111.
1 parent ea60dd3 commit cfdd7cf

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

src/components/fabSpeedDial/fabController.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
setupDefaults();
3030
setupListeners();
3131
setupWatchers();
32+
33+
var initialAnimationAttempts = 0;
3234
fireInitialAnimations();
3335

3436
function setupDefaults() {
@@ -40,6 +42,9 @@
4042

4143
// Start the keyboard interaction at the first action
4244
resetActionIndex();
45+
46+
// Add an animations waiting class so we know not to run
47+
$element.addClass('md-animations-waiting');
4348
}
4449

4550
function setupListeners() {
@@ -133,11 +138,23 @@
133138
});
134139
}
135140

136-
// Fire the animations once in a separate digest loop to initialize them
137141
function fireInitialAnimations() {
138-
$mdUtil.nextTick(function() {
139-
$animate.addClass($element, 'md-noop');
140-
});
142+
// If the element is actually visible on the screen
143+
if ($element[0].scrollHeight > 0) {
144+
// Fire our animation
145+
$animate.addClass($element, 'md-animations-ready').then(function() {
146+
// Remove the waiting class
147+
$element.removeClass('md-animations-waiting');
148+
});
149+
}
150+
151+
// Otherwise, try for up to 1 second before giving up
152+
else if (initialAnimationAttempts < 10) {
153+
$timeout(fireInitialAnimations, 100);
154+
155+
// Increment our counter
156+
initialAnimationAttempts = initialAnimationAttempts + 1;
157+
}
141158
}
142159

143160
function enableKeyboard() {

src/components/fabSpeedDial/fabSpeedDial.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
function delayDone(done) { $timeout(done, cssAnimationDuration, false); }
115115

116116
function runAnimation(element) {
117+
// Don't run if we are still waiting and we are not ready
118+
if (element.hasClass('md-animations-waiting') && !element.hasClass('md-animations-ready')) {
119+
return;
120+
}
121+
117122
var el = element[0];
118123
var ctrl = element.controller('mdFabSpeedDial');
119124
var items = el.querySelectorAll('.md-fab-action-item');
@@ -184,8 +189,10 @@
184189
addClass: function(element, className, done) {
185190
if (element.hasClass('md-fling')) {
186191
runAnimation(element);
192+
delayDone(done);
193+
} else {
194+
done();
187195
}
188-
delayDone(done);
189196
},
190197
removeClass: function(element, className, done) {
191198
runAnimation(element);

src/components/fabSpeedDial/fabSpeedDial.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,22 @@ md-fab-speed-dial {
118118
/*
119119
* Handle the animations
120120
*/
121-
&.md-scale {
121+
&.md-fling {
122+
.md-fab-action-item {
123+
opacity: 1;
124+
}
125+
}
126+
127+
// For the initial animation, set the duration to be instant
128+
&.md-fling.md-animations-waiting {
122129
.md-fab-action-item {
123130
opacity: 0;
131+
transition-duration: 0s;
132+
}
133+
}
134+
135+
&.md-scale {
136+
.md-fab-action-item {
124137
transform: scale(0.1);
125138
transition: $swift-ease-in;
126139

0 commit comments

Comments
 (0)