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

Commit d491cfd

Browse files
committed
fix(fabSpeedDial): fix $digest in-progress error when opening a dialog
cebor reported a $digest in progress bug when trying to open a dialog from within the speed dial; haven't figured out how to create a test that demonstrates it, but I added a demo which shows failure references #3213
1 parent 9bc58b1 commit d491cfd

File tree

5 files changed

+95
-9
lines changed

5 files changed

+95
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div ng-controller="AppCtrl" layout="column">
2+
<md-content class="md-padding" layout="column">
3+
<p>
4+
You can also use the buttons to open a dialog.
5+
</p>
6+
7+
<div class="lock-size" layout="row" layout-align="center center">
8+
<md-fab-speed-dial md-direction="down" class="md-fling">
9+
<md-fab-trigger>
10+
<md-button aria-label="Menu" class="md-fab md-warn">
11+
<md-tooltip md-direction="top">Menu</md-tooltip>
12+
<md-icon md-svg-src="img/icons/menu.svg"></md-icon>
13+
</md-button>
14+
</md-fab-trigger>
15+
16+
<md-fab-actions>
17+
<md-button aria-label="Open dialog" class="md-fab md-raised md-mini"
18+
ng-click="demo.openDialog($event)">
19+
<md-tooltip md-direction="left">Open dialog</md-tooltip>
20+
<md-icon md-svg-src="img/icons/launch.svg"></md-icon>
21+
</md-button>
22+
</md-fab-actions>
23+
</md-fab-speed-dial>
24+
</div>
25+
</md-content>
26+
27+
<script type="text/ng-template" id="dialog.html">
28+
<md-dialog>
29+
<md-dialog-content>Hello User!!!</md-dialog-content>
30+
31+
<div class="md-actions">
32+
<md-button aria-label="Close dialog" ng-click="dialog.close()" class="md-primary">
33+
Close Greeting
34+
</md-button>
35+
36+
<md-button aria-label="Submit dialog" ng-click="dialog.submit()" class="md-primary">
37+
Submit
38+
</md-button>
39+
</div>
40+
</md-dialog>
41+
</script>
42+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(function() {
2+
'use strict';
3+
4+
angular.module('fabSpeedDialModalDemo', ['ngMaterial'])
5+
.controller('AppCtrl', function($scope, $mdDialog) {
6+
$scope.demo = {
7+
openDialog: function($event) {
8+
$mdDialog.show({
9+
clickOutsideToClose: true,
10+
controller: function($mdDialog) {
11+
this.close = function() {
12+
$mdDialog.cancel();
13+
};
14+
this.submit = function() {
15+
$mdDialog.hide();
16+
};
17+
},
18+
controllerAs: 'dialog',
19+
templateUrl: 'dialog.html',
20+
targetEvent: $event
21+
});
22+
}
23+
};
24+
});
25+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.md-fab.md-mini {
2+
background-color: #aaa !important;
3+
}
4+
5+
.md-fab:hover, .md-fab.md-focused {
6+
background-color: #333 !important;
7+
}
8+
9+
.lock-size {
10+
min-width: 300px;
11+
min-height: 300px;
12+
width: 300px;
13+
height: 300px;
14+
margin-left: auto;
15+
margin-right: auto;
16+
}

src/components/fabSpeedDial/fabSpeedDial.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@
7979
// Define our open/close functions
8080
// Note: Used by fabTrigger and fabActions directives
8181
vm.open = function() {
82-
vm.shouldClose = false;
83-
$scope.$apply('vm.isOpen = true');
82+
// Run in a timeout to avoid conflicts with existing digest loops
83+
$timeout(function() {
84+
vm.isOpen = true;
85+
});
8486
};
8587

8688
vm.close = function() {
87-
vm.shouldClose = true;
88-
89-
// Run at the next digest to avoid very fast changes (i.e. tabbing between child items)
89+
// Run in a timeout to avoid conflicts with existing digest loops
9090
$timeout(function() {
9191
// Only close if we do not currently have mouse focus (since child elements can call this)
92-
!vm.moused && vm.shouldClose && $scope.$apply('vm.isOpen = false');
93-
}, 0, false);
92+
!vm.moused && (vm.isOpen = false);
93+
});
9494
};
9595

9696
vm.mouseenter = function() {

src/components/fabSpeedDial/fabSpeedDial.spec.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,23 @@ describe('<md-fab-speed-dial> directive', function() {
3232
expect(element.hasClass('md-right')).toBe(true);
3333
}));
3434

35-
it('opens when the trigger element is focused', inject(function() {
35+
it('opens when the trigger element is focused', inject(function($timeout) {
3636
compileAndLink(
3737
'<md-fab-speed-dial><md-fab-trigger><button></button></md-fab-trigger></md-fab-speed-dial>'
3838
);
3939

4040
element.find('button').triggerHandler('focus');
41+
$timeout.flush();
4142
expect(controller.isOpen).toBe(true);
4243
}));
4344

44-
it('opens when the speed dial elements are focused', inject(function() {
45+
it('opens when the speed dial elements are focused', inject(function($timeout) {
4546
compileAndLink(
4647
'<md-fab-speed-dial><md-fab-actions><button></button></md-fab-actions></md-fab-speed-dial>'
4748
);
4849

4950
element.find('button').triggerHandler('focus');
51+
$timeout.flush();
5052
expect(controller.isOpen).toBe(true);
5153
}));
5254

@@ -56,6 +58,7 @@ describe('<md-fab-speed-dial> directive', function() {
5658
);
5759

5860
element.find('button').triggerHandler('focus');
61+
$timeout.flush();
5962
expect(controller.isOpen).toBe(true);
6063

6164
element.find('button').triggerHandler('blur');

0 commit comments

Comments
 (0)