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

Commit b65d153

Browse files
fix(tooltip): trigger parent blur on leaveHandler( )
`md-button` with tooltip should not continue to display focus style after mouseleave and tooltip hide. Fixes #4249. Fixes #4597. Closes #4590.
1 parent 7d8b99f commit b65d153

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

src/components/button/button.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $timeout) {
116116
}, 100);
117117
})
118118
.on('focus', function() {
119-
if (scope.mouseActive === false) { element.addClass('md-focused'); }
119+
if (scope.mouseActive === false) {
120+
element.addClass('md-focused');
121+
}
120122
})
121-
.on('blur', function() { element.removeClass('md-focused'); });
123+
.on('blur', function(ev) {
124+
element.removeClass('md-focused');
125+
});
122126
}
123127

124128
}

src/components/tooltip/tooltip.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
160160
var autohide = scope.hasOwnProperty('autohide') ? scope.autohide : attr.hasOwnProperty('mdAutohide');
161161
if (autohide || mouseActive || ($document[0].activeElement !== parent[0]) ) {
162162
parent.off('blur mouseleave touchend touchcancel', leaveHandler );
163+
parent.triggerHandler("blur");
163164
setVisible(false);
164165
}
165166
mouseActive = false;

src/core/services/ripple/button_ripple.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@
1111
*
1212
* @param {object=} scope Scope within the current context
1313
* @param {object=} element The element the ripple effect should be applied to
14-
* @param {object=} options (Optional) Configuration options to override the defaultripple configuration
14+
* @param {object=} options (Optional) Configuration options to override the default ripple configuration
1515
*/
1616

1717
angular.module('material.core')
1818
.factory('$mdButtonInkRipple', MdButtonInkRipple);
1919

2020
function MdButtonInkRipple($mdInkRipple) {
2121
return {
22-
attach: attach
23-
};
22+
attach: function attachRipple(scope, element, options) {
23+
options = angular.extend(optionsForElement(element), options);
2424

25-
function attach(scope, element, options) {
26-
var elementOptions = optionsForElement(element);
27-
return $mdInkRipple.attach(scope, element, angular.extend(elementOptions, options));
25+
return $mdInkRipple.attach(scope, element, options);
26+
}
2827
};
2928

3029
function optionsForElement(element) {

src/core/services/ripple/ripple.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ InkRippleCtrl.prototype.bindEvents = function () {
140140
* @param event {MouseEvent}
141141
*/
142142
InkRippleCtrl.prototype.handleMousedown = function (event) {
143+
if ( this.mousedown ) return;
144+
143145
// When jQuery is loaded, we have to get the original event
144146
if (event.hasOwnProperty('originalEvent')) event = event.originalEvent;
145147
this.mousedown = true;
@@ -156,17 +158,23 @@ InkRippleCtrl.prototype.handleMousedown = function (event) {
156158
* mouseup or mouseleave event)
157159
*/
158160
InkRippleCtrl.prototype.handleMouseup = function () {
159-
var ctrl = this;
160-
this.mousedown = false;
161-
this.$mdUtil.nextTick(function () { ctrl.clearRipples(); }, false);
161+
if ( this.mousedown || this.lastRipple ) {
162+
var ctrl = this;
163+
this.mousedown = false;
164+
this.$mdUtil.nextTick(function () {
165+
ctrl.clearRipples();
166+
}, false);
167+
}
162168
};
163169

164170
/**
165171
* Cycles through all ripples and attempts to remove them.
166172
* Depending on logic within `fadeInComplete`, some removals will be postponed.
167173
*/
168174
InkRippleCtrl.prototype.clearRipples = function () {
169-
for (var i = 0; i < this.ripples.length; i++) this.fadeInComplete(this.ripples[ i ]);
175+
for (var i = 0; i < this.ripples.length; i++) {
176+
this.fadeInComplete(this.ripples[ i ]);
177+
}
170178
};
171179

172180
/**
@@ -222,9 +230,14 @@ InkRippleCtrl.prototype.createRipple = function (left, top) {
222230
this.container.append(ripple);
223231
this.ripples.push(ripple);
224232
ripple.addClass('md-ripple-placed');
233+
225234
this.$mdUtil.nextTick(function () {
235+
226236
ripple.addClass('md-ripple-scaled md-ripple-active');
227-
ctrl.$timeout(function () { ctrl.clearRipples(); }, DURATION, false);
237+
ctrl.$timeout(function () {
238+
ctrl.clearRipples();
239+
}, DURATION, false);
240+
228241
}, false);
229242

230243
function rgbaToRGB (color) {
@@ -246,7 +259,9 @@ InkRippleCtrl.prototype.createRipple = function (left, top) {
246259
*/
247260
InkRippleCtrl.prototype.fadeInComplete = function (ripple) {
248261
if (this.lastRipple === ripple) {
249-
if (!this.timeout && !this.mousedown) this.removeRipple(ripple);
262+
if (!this.timeout && !this.mousedown) {
263+
this.removeRipple(ripple);
264+
}
250265
} else {
251266
this.removeRipple(ripple);
252267
}
@@ -265,14 +280,19 @@ InkRippleCtrl.prototype.removeRipple = function (ripple) {
265280
if (this.ripples.length === 0) this.container.css({ backgroundColor: '' });
266281
// use a 2-second timeout in order to allow for the animation to finish
267282
// we don't actually care how long the animation takes
268-
this.$timeout(function () { ctrl.fadeOutComplete(ripple); }, DURATION, false);
283+
this.$timeout(function () {
284+
ctrl.fadeOutComplete(ripple);
285+
}, DURATION, false);
269286
};
270287

271288
/**
272289
* Removes the provided ripple from the DOM
273290
* @param ripple
274291
*/
275-
InkRippleCtrl.prototype.fadeOutComplete = function (ripple) { ripple.remove(); };
292+
InkRippleCtrl.prototype.fadeOutComplete = function (ripple) {
293+
ripple.remove();
294+
this.lastRipple = null;
295+
};
276296

277297
/**
278298
* Used to create an empty directive. This is used to track flag-directives whose children may have

0 commit comments

Comments
 (0)