diff --git a/paper-tooltip.js b/paper-tooltip.js index 9476bc8..36f28be 100644 --- a/paper-tooltip.js +++ b/paper-tooltip.js @@ -314,12 +314,15 @@ Polymer({ /** * Returns the target element that this tooltip is anchored to. It is - * either the element given by the `for` attribute, or the immediate parent - * of the tooltip. + * the element given by the `for` attribute, the element manually specified + * through the `target` attribute, or the immediate parent of the tooltip. * * @type {Node} */ get target() { + if (this._manualTarget) + return this._manualTarget; + var parentNode = dom(this).parentNode; // If the parentNode is a document fragment, then we need to use the host. var ownerRoot = dom(this).getOwnerRoot(); @@ -334,6 +337,15 @@ Polymer({ return target; }, + /** + * Sets the target element that this tooltip will be anchored to. + * @param {Node} target + */ + set target(target) { + this._manualTarget = target; + this._findTarget(); + }, + /** * @return {void} */ diff --git a/test/basic.html b/test/basic.html index fe86f40..a284df1 100644 --- a/test/basic.html +++ b/test/basic.html @@ -22,11 +22,16 @@ margin: 0; padding: 0; } - #target { + #target, #target1 { width: 100px; height: 20px; background-color: red; } + #target2 { + width: 120px; + height: 30px; + background-color: blue; + } paper-tooltip { width: 70px; height: 30px; @@ -118,6 +123,18 @@ + + + +