Bug 1461522 - Add ID and class properties to HTMLTooltip; r?jdescottes
In particular, the ID allows us to associate the tooltip with the button that
triggers it using the aria-controls attribute.
MozReview-Commit-ID: ArjH2s5JNlC
--- a/devtools/client/shared/widgets/tooltip/HTMLTooltip.js
+++ b/devtools/client/shared/widgets/tooltip/HTMLTooltip.js
@@ -279,37 +279,46 @@ const getRelativeRect = function(node, r
};
/**
* The HTMLTooltip can display HTML content in a tooltip popup.
*
* @param {Document} toolboxDoc
* The toolbox document to attach the HTMLTooltip popup.
* @param {Object}
+ * - {String} id
+ * The ID to assign to the tooltip container elment.
+ * - {String} className
+ * A string separated list of classes to add to the tooltip container
+ * element.
* - {String} type
* Display type of the tooltip. Possible values: "normal", "arrow", and
* "doorhanger".
* - {Boolean} autofocus
* Defaults to false. Should the tooltip be focused when opening it.
* - {Boolean} consumeOutsideClicks
* Defaults to true. The tooltip is closed when clicking outside.
* Should this event be stopped and consumed or not.
* - {Boolean} useXulWrapper
* Defaults to false. If the tooltip is hosted in a XUL document, use a XUL panel
* in order to use all the screen viewport available.
*/
function HTMLTooltip(toolboxDoc, {
+ id = "",
+ className = "",
type = "normal",
autofocus = false,
consumeOutsideClicks = true,
useXulWrapper = false,
} = {}) {
EventEmitter.decorate(this);
this.doc = toolboxDoc;
+ this.id = id;
+ this.className = className;
this.type = type;
this.autofocus = autofocus;
this.consumeOutsideClicks = consumeOutsideClicks;
this.useXulWrapper = this._isXUL() && useXulWrapper;
this.preferredWidth = "auto";
this.preferredHeight = "auto";
// The top window is used to attach click event listeners to close the tooltip if the
@@ -697,17 +706,25 @@ HTMLTooltip.prototype = {
this.xulPanelWrapper.remove();
}
this._toggle.destroy();
},
_createContainer: function() {
const container = this.doc.createElementNS(XHTML_NS, "div");
container.setAttribute("type", this.type);
+
+ if (this.id) {
+ container.setAttribute("id", this.id);
+ }
+
container.classList.add("tooltip-container");
+ if (this.className) {
+ container.classList.add(...this.className.split(" "));
+ }
let html = '<div class="tooltip-filler"></div>';
html += '<div class="tooltip-panel"></div>';
if (this.type === TYPE.ARROW || this.type === TYPE.DOORHANGER) {
html += '<div class="tooltip-arrow"></div>';
}
// eslint-disable-next-line no-unsanitized/property