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

Commit c513e49

Browse files
devversionThomasBurleson
authored andcommitted
fix(tooltip): empty tooltips should not show up.
Fixes #8021.
1 parent f667069 commit c513e49

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/components/tooltip/tooltip.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
274274
}
275275

276276
function showTooltip() {
277+
// Do not show the tooltip if the text is empty.
278+
if (!element[0].textContent.trim()) return;
279+
277280
// Insert the element and position at top left, so we can get the position
278281
// and check if we should display it
279282
element.css({top: 0, left: 0});

src/components/tooltip/tooltip.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,33 @@ describe('<md-tooltip> directive', function() {
165165
expect($rootScope.testModel.isVisible).toBe(false);
166166
});
167167

168+
it('should not show when the text is empty', function() {
169+
170+
expect(findTooltip().length).toBe(0);
171+
172+
buildTooltip(
173+
'<md-button>' +
174+
'Hello' +
175+
'<md-tooltip md-visible="testModel.isVisible">{{ textContent }} </md-tooltip>' +
176+
'</md-button>'
177+
);
178+
179+
showTooltip(true);
180+
181+
expect(findTooltip().length).toBe(0);
182+
183+
$rootScope.textContent = 'Tooltip';
184+
$rootScope.$apply();
185+
186+
// Trigger a change on the model, otherwise the tooltip component can't detect the
187+
// change.
188+
showTooltip(false);
189+
showTooltip(true);
190+
191+
expect(findTooltip().length).toBe(1);
192+
expect(findTooltip().hasClass('_md-show')).toBe(true);
193+
});
194+
168195
it('should set visible on focus and blur', function() {
169196
buildTooltip(
170197
'<md-button>' +

0 commit comments

Comments
 (0)