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

Commit 9d72659

Browse files
EladBezaleljelbourn
authored andcommitted
fix(tooltip): always append to body and disappear on scroll
- Default animation origin has been set to bottom that mean the origin is `top center` Closes #6140
1 parent db72b39 commit 9d72659

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/components/tooltip/tooltip.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
5858

5959
var parent = $mdUtil.getParentWithPointerEvents(element),
6060
content = angular.element(element[0].getElementsByClassName('md-content')[0]),
61-
current = $mdUtil.getNearestContentElement(element),
62-
tooltipParent = angular.element(current || document.body),
61+
tooltipParent = angular.element(document.body),
6362
debouncedOnResize = $$rAF.throttle(function () { updatePosition(); });
6463

64+
if ($animate.pin) $animate.pin(element, parent);
65+
6566
// Initialize element
6667

6768
setDefaults();
6869
manipulateElement();
6970
bindEvents();
7071

71-
// Default origin transform point is 'left top'
72-
// positionTooltip() is always relative to top left
72+
// Default origin transform point is 'center top'
73+
// positionTooltip() is always relative to center top
7374
updateContentOrigin();
7475

7576
configureWatchers();
@@ -81,7 +82,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
8182
}
8283

8384
function updateContentOrigin() {
84-
var origin = 'left top';
85+
var origin = 'center top';
8586
switch (scope.direction) {
8687
case 'left' : origin = 'right center'; break;
8788
case 'right' : origin = 'left center'; break;
@@ -137,19 +138,25 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
137138
});
138139

139140
attributeObserver.observe(parent[0], { attributes: true});
140-
};
141+
}
141142

142143
// Store whether the element was focused when the window loses focus.
143144
var windowBlurHandler = function() {
144145
elementFocusedOnWindowBlur = document.activeElement === parent[0];
145146
};
146147
var elementFocusedOnWindowBlur = false;
147148

149+
function windowScrollHandler() {
150+
setVisible(false);
151+
}
152+
148153
ngWindow.on('blur', windowBlurHandler);
149154
ngWindow.on('resize', debouncedOnResize);
155+
document.addEventListener('scroll', windowScrollHandler, true);
150156
scope.$on('$destroy', function() {
151157
ngWindow.off('blur', windowBlurHandler);
152158
ngWindow.off('resize', debouncedOnResize);
159+
document.removeEventListener('scroll', windowScrollHandler, true);
153160
attributeObserver && attributeObserver.disconnect();
154161
});
155162

src/components/tooltip/tooltip.scss

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ md-tooltip {
4848
&.md-show, &.md-show-add-active {
4949
transform: scale(1);
5050
opacity: 1;
51+
transform-origin: center top;
5152
}
5253
&.md-show-remove {
5354
transition: $swift-ease-out;

0 commit comments

Comments
 (0)