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

fix(tooltip): always append to body and disappear on scroll #6140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
19 changes: 13 additions & 6 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe

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

if ($animate.pin) $animate.pin(element, parent);

// Initialize element

setDefaults();
manipulateElement();
bindEvents();

// Default origin transform point is 'left top'
// positionTooltip() is always relative to top left
// Default origin transform point is 'center top'
// positionTooltip() is always relative to center top
updateContentOrigin();

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

function updateContentOrigin() {
var origin = 'left top';
var origin = 'center top';
switch (scope.direction) {
case 'left' : origin = 'right center'; break;
case 'right' : origin = 'left center'; break;
Expand Down Expand Up @@ -137,19 +138,25 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
});

attributeObserver.observe(parent[0], { attributes: true});
};
}

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

function windowScrollHandler() {
setVisible(false);
}

ngWindow.on('blur', windowBlurHandler);
ngWindow.on('resize', debouncedOnResize);
document.addEventListener('scroll', windowScrollHandler, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this on Firefox? Scrolling behavior is slightly different there.

I still suspect that something is doing stopProagation on the scroll event...

Copy link

@michahell michahell Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably causing the bug on firefox (at least in 1.09) where tooltips flash and immediately get removed...

scope.$on('$destroy', function() {
ngWindow.off('blur', windowBlurHandler);
ngWindow.off('resize', debouncedOnResize);
document.removeEventListener('scroll', windowScrollHandler, true);
attributeObserver && attributeObserver.disconnect();
});

Expand Down
1 change: 1 addition & 0 deletions src/components/tooltip/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ md-tooltip {
&.md-show, &.md-show-add-active {
transform: scale(1);
opacity: 1;
transform-origin: center top;
}
&.md-show-remove {
transition: $swift-ease-out;
Expand Down