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

feat(tooltip): add configurable tooltip delay #713

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ angular.module('material.components.tooltip', [
*
* @param {expression=} mdVisible Boolean bound to whether the tooltip is
* currently visible.
* @param {number=} [mdTooltipDelay=400] Number of milliseconds to delay showing
* tooltip.
*/
function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdTheming) {

Expand All @@ -49,14 +51,16 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
'<div class="md-background"></div>' +
'<div class="md-content" ng-transclude></div>',
scope: {
visible: '=?mdVisible'
visible: '=?mdVisible',
delay: '=?mdTooltipDelay'
},
link: postLink
};

function postLink(scope, element, attr, contentCtrl) {
$mdTheming(element);
var parent = element.parent();
scope.delay = scope.delay || TOOLTIP_SHOW_DELAY;

// We will re-attach tooltip when visible
element.detach();
Expand Down Expand Up @@ -94,7 +98,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
// Methods
// *******

// If setting visible to true, debounce to TOOLTIP_SHOW_DELAY ms
// If setting visible to true, debounce to scope.delay ms
// If setting visible to false and no timeout is active, instantly hide the tooltip.
function setVisible(value) {
setVisible.value = !!value;
Expand All @@ -105,7 +109,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
$timeout(function() {
scope.visible = setVisible.value;
setVisible.queued = false;
}, TOOLTIP_SHOW_DELAY);
}, scope.delay);

} else {
$timeout(function() { scope.visible = false; });
Expand Down