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

Commit

Permalink
fix(tooltip): empty tooltips should not show up.
Browse files Browse the repository at this point in the history
Fixes #8021.
  • Loading branch information
devversion authored and ThomasBurleson committed May 11, 2016
1 parent f667069 commit c513e49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
}

function showTooltip() {
// Do not show the tooltip if the text is empty.
if (!element[0].textContent.trim()) return;

// Insert the element and position at top left, so we can get the position
// and check if we should display it
element.css({top: 0, left: 0});
Expand Down
27 changes: 27 additions & 0 deletions src/components/tooltip/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,33 @@ describe('<md-tooltip> directive', function() {
expect($rootScope.testModel.isVisible).toBe(false);
});

it('should not show when the text is empty', function() {

expect(findTooltip().length).toBe(0);

buildTooltip(
'<md-button>' +
'Hello' +
'<md-tooltip md-visible="testModel.isVisible">{{ textContent }} </md-tooltip>' +
'</md-button>'
);

showTooltip(true);

expect(findTooltip().length).toBe(0);

$rootScope.textContent = 'Tooltip';
$rootScope.$apply();

// Trigger a change on the model, otherwise the tooltip component can't detect the
// change.
showTooltip(false);
showTooltip(true);

expect(findTooltip().length).toBe(1);
expect(findTooltip().hasClass('_md-show')).toBe(true);
});

it('should set visible on focus and blur', function() {
buildTooltip(
'<md-button>' +
Expand Down

0 comments on commit c513e49

Please sign in to comment.