Skip to content

Commit

Permalink
fix(tooltip): trigger parent blur on leaveHandler( )
Browse files Browse the repository at this point in the history
`md-button` with tooltip should not continue to display focus style after mouseleave and tooltip hide.

Fixes angular#4249. Fixes angular#4597. Closes angular#4590.
  • Loading branch information
ThomasBurleson authored and kennethcachia committed Sep 23, 2015
1 parent 354e0c1 commit 1156734
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
8 changes: 6 additions & 2 deletions src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $timeout) {
}, 100);
})
.on('focus', function() {
if (scope.mouseActive === false) { element.addClass('md-focused'); }
if (scope.mouseActive === false) {
element.addClass('md-focused');
}
})
.on('blur', function() { element.removeClass('md-focused'); });
.on('blur', function(ev) {
element.removeClass('md-focused');
});
}

}
1 change: 1 addition & 0 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
var autohide = scope.hasOwnProperty('autohide') ? scope.autohide : attr.hasOwnProperty('mdAutohide');
if (autohide || mouseActive || ($document[0].activeElement !== parent[0]) ) {
parent.off('blur mouseleave touchend touchcancel', leaveHandler );
parent.triggerHandler("blur");
setVisible(false);
}
mouseActive = false;
Expand Down
11 changes: 5 additions & 6 deletions src/core/services/ripple/button_ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
*
* @param {object=} scope Scope within the current context
* @param {object=} element The element the ripple effect should be applied to
* @param {object=} options (Optional) Configuration options to override the defaultripple configuration
* @param {object=} options (Optional) Configuration options to override the default ripple configuration
*/

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

function MdButtonInkRipple($mdInkRipple) {
return {
attach: attach
};
attach: function attachRipple(scope, element, options) {
options = angular.extend(optionsForElement(element), options);

function attach(scope, element, options) {
var elementOptions = optionsForElement(element);
return $mdInkRipple.attach(scope, element, angular.extend(elementOptions, options));
return $mdInkRipple.attach(scope, element, options);
}
};

function optionsForElement(element) {
Expand Down
36 changes: 28 additions & 8 deletions src/core/services/ripple/ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ InkRippleCtrl.prototype.bindEvents = function () {
* @param event {MouseEvent}
*/
InkRippleCtrl.prototype.handleMousedown = function (event) {
if ( this.mousedown ) return;

// When jQuery is loaded, we have to get the original event
if (event.hasOwnProperty('originalEvent')) event = event.originalEvent;
this.mousedown = true;
Expand All @@ -156,17 +158,23 @@ InkRippleCtrl.prototype.handleMousedown = function (event) {
* mouseup or mouseleave event)
*/
InkRippleCtrl.prototype.handleMouseup = function () {
var ctrl = this;
this.mousedown = false;
this.$mdUtil.nextTick(function () { ctrl.clearRipples(); }, false);
if ( this.mousedown || this.lastRipple ) {
var ctrl = this;
this.mousedown = false;
this.$mdUtil.nextTick(function () {
ctrl.clearRipples();
}, false);
}
};

/**
* Cycles through all ripples and attempts to remove them.
* Depending on logic within `fadeInComplete`, some removals will be postponed.
*/
InkRippleCtrl.prototype.clearRipples = function () {
for (var i = 0; i < this.ripples.length; i++) this.fadeInComplete(this.ripples[ i ]);
for (var i = 0; i < this.ripples.length; i++) {
this.fadeInComplete(this.ripples[ i ]);
}
};

/**
Expand Down Expand Up @@ -222,9 +230,14 @@ InkRippleCtrl.prototype.createRipple = function (left, top) {
this.container.append(ripple);
this.ripples.push(ripple);
ripple.addClass('md-ripple-placed');

this.$mdUtil.nextTick(function () {

ripple.addClass('md-ripple-scaled md-ripple-active');
ctrl.$timeout(function () { ctrl.clearRipples(); }, DURATION, false);
ctrl.$timeout(function () {
ctrl.clearRipples();
}, DURATION, false);

}, false);

function rgbaToRGB (color) {
Expand All @@ -246,7 +259,9 @@ InkRippleCtrl.prototype.createRipple = function (left, top) {
*/
InkRippleCtrl.prototype.fadeInComplete = function (ripple) {
if (this.lastRipple === ripple) {
if (!this.timeout && !this.mousedown) this.removeRipple(ripple);
if (!this.timeout && !this.mousedown) {
this.removeRipple(ripple);
}
} else {
this.removeRipple(ripple);
}
Expand All @@ -265,14 +280,19 @@ InkRippleCtrl.prototype.removeRipple = function (ripple) {
if (this.ripples.length === 0) this.container.css({ backgroundColor: '' });
// use a 2-second timeout in order to allow for the animation to finish
// we don't actually care how long the animation takes
this.$timeout(function () { ctrl.fadeOutComplete(ripple); }, DURATION, false);
this.$timeout(function () {
ctrl.fadeOutComplete(ripple);
}, DURATION, false);
};

/**
* Removes the provided ripple from the DOM
* @param ripple
*/
InkRippleCtrl.prototype.fadeOutComplete = function (ripple) { ripple.remove(); };
InkRippleCtrl.prototype.fadeOutComplete = function (ripple) {
ripple.remove();
this.lastRipple = null;
};

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

0 comments on commit 1156734

Please sign in to comment.