diegoles / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

Tooltip.setPosition does not set position #512

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. Create a tooltip. var tooltip = new goog.ui.Tooltip(el);
2. Create a positioning type. var pos = new 
goog.positioning.AbsolutePosition(new goog.math.Coordinate(100, 100))
3. Set the position of the tooltip. tooltip.setPosition(pos);

What is the expected output? What do you see instead?
The tooltip should be displayed in the position supplied. The tooltip is 
actually displayed at the cursor point.

This seems to be caused by the position_ attribute not being supplied to the 
startShowTimer method.

The below patch appears to fix the problem (in tooltip.js):

--- a/tooltip.js
+++ b/tooltip.js
@@ -667,7 +667,7 @@ goog.ui.Tooltip.prototype.handleMouseOver = function(event) 
{
   this.clearHideTimer();
   if (el != this.anchor) {
     this.anchor = el;
-    this.startShowTimer(/** @type {Element} */ (el));
+    this.startShowTimer(/** @type {Element} */ (el), this.position_);
     this.checkForParentTooltip_();
     this.saveCursorPosition_(event);
   }
@@ -726,7 +726,7 @@ goog.ui.Tooltip.prototype.handleFocus = function(event) {

   if (this.anchor != el) {
     this.anchor = el;
-    var pos = this.getPositioningStrategy(goog.ui.Tooltip.Activation.FOCUS);
+    var pos = this.position_ || 
this.getPositioningStrategy(goog.ui.Tooltip.Activation.FOCUS);
     this.clearHideTimer();
     this.startShowTimer(/** @type {Element} */ (el), pos);

Original issue reported on code.google.com by neale...@gmail.com on 12 Nov 2012 at 1:05

GoogleCodeExporter commented 8 years ago
This is the expected behavior.

setPosition is intended to be used with setVisible (both part of the 
goog.ui.Popup interface). 

If the hover/focus events where to use set set position then the tooltip would 
always be displayed at the given position rather than at the position of the 
active element circumventing the tooltip logic.

To display a tooltip at a fixed position either use goog.ui.Popup, use the  
setPosition/setVisible API or subclass the tooltip class to override the 
positioning logic.

Original comment by e...@google.com on 20 May 2013 at 7:01