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

Commit 14eebf4

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(speedDial): non-fab clicks no longer close immediately
In the demo application and some user's apps, the `md-open` attribute was bound to an input element, but clicking this element while the FAB Speed Dial was open would open and then immediately close the speed dial since the user clicked outside of the speed dial. Fix by delaying the check for outside clicks until the next digest loop. Also fix a tiny positioning issue with the fling animation. Fixes #5243. Closes #5440.
1 parent a8537e6 commit 14eebf4

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/components/fabSpeedDial/demoBasicUsage/index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@
4343
<div layout="column" layout-align="start center">
4444
<b>Open/Closed</b>
4545

46-
<md-radio-group ng-model="demo.isOpen">
47-
<md-radio-button ng-value="true">Open</md-radio-button>
48-
<md-radio-button ng-value="false">Closed</md-radio-button>
49-
</md-radio-group>
46+
<md-checkbox ng-model="demo.isOpen">
47+
Open
48+
</md-checkbox>
5049
</div>
5150

5251
<div layout="column" layout-align="start center">

src/components/fabSpeedDial/fabController.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
function FabController($scope, $element, $animate, $mdUtil, $mdConstant, $timeout) {
88
var vm = this;
99

10-
// NOTE: We use async evals below to avoid conflicts with any existing digest loops
10+
// NOTE: We use async eval(s) below to avoid conflicts with any existing digest loops
1111

1212
vm.open = function() {
1313
$scope.$evalAsync("vm.isOpen = true");
@@ -142,8 +142,12 @@
142142

143143
function enableKeyboard() {
144144
$element.on('keydown', keyPressed);
145-
angular.element(document).on('click', checkForOutsideClick);
146-
angular.element(document).on('touchend', checkForOutsideClick);
145+
146+
// On the next tick, setup a check for outside clicks; we do this on the next tick to avoid
147+
// clicks/touches that result in the isOpen attribute changing (e.g. a bound radio button)
148+
$mdUtil.nextTick(function() {
149+
angular.element(document).on('click touchend', checkForOutsideClick);
150+
});
147151

148152
// TODO: On desktop, we should be able to reset the indexes so you cannot tab through, but
149153
// this breaks accessibility, especially on mobile, since you have no arrow keys to press
@@ -152,8 +156,7 @@
152156

153157
function disableKeyboard() {
154158
$element.off('keydown', keyPressed);
155-
angular.element(document).off('click', checkForOutsideClick);
156-
angular.element(document).off('touchend', checkForOutsideClick);
159+
angular.element(document).off('click touchend', checkForOutsideClick);
157160
}
158161

159162
function checkForOutsideClick(event) {

src/components/fabSpeedDial/fabSpeedDial.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,27 @@
148148
var newPosition, axis;
149149
var styles = item.style;
150150

151+
// Make sure to account for differences in the dimensions of the trigger verses the items
152+
// so that we can properly center everything; this helps hide the item's shadows behind
153+
// the trigger.
154+
var triggerItemHeightOffset = (triggerElement.clientHeight - item.clientHeight) / 2;
155+
var triggerItemWidthOffset = (triggerElement.clientWidth - item.clientWidth) / 2;
156+
151157
switch (ctrl.direction) {
152158
case 'up':
153-
newPosition = item.scrollHeight * (index + 1);
159+
newPosition = (item.scrollHeight * (index + 1) + triggerItemHeightOffset);
154160
axis = 'Y';
155161
break;
156162
case 'down':
157-
newPosition = -item.scrollHeight * (index + 1);
163+
newPosition = -(item.scrollHeight * (index + 1) + triggerItemHeightOffset);
158164
axis = 'Y';
159165
break;
160166
case 'left':
161-
newPosition = item.scrollWidth * (index + 1);
167+
newPosition = (item.scrollWidth * (index + 1) + triggerItemWidthOffset);
162168
axis = 'X';
163169
break;
164170
case 'right':
165-
newPosition = -item.scrollWidth * (index + 1);
171+
newPosition = -(item.scrollWidth * (index + 1) + triggerItemWidthOffset);
166172
axis = 'X';
167173
break;
168174
}

0 commit comments

Comments
 (0)