Skip to content

Commit

Permalink
💄 Add tooltip element to XUL menugroups
Browse files Browse the repository at this point in the history
  • Loading branch information
kierandrewett committed Feb 2, 2024
1 parent 8686d54 commit 98a00cd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions components/menus/content/xul-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
this
);

Services.scriptloader.loadSubScript(
"chrome://dot/content/widgets/xul-menugroup.js",
this
);

class MozMenu extends MozMenuBaseMixin(
MozElements.MozElementMixin(XULMenuElement)
) {
Expand Down
44 changes: 43 additions & 1 deletion components/menus/content/xul-menugroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,49 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

{
class MozMenuGroup extends MozXULElement {}
class MozMenuGroup extends MozXULElement {
/**
* The menu group's tooltip element
*/
get groupTooltip() {
return /** @type {BrowserTooltip} */ (
this.querySelector("tooltip") ||
document.createXULElement("tooltip", {
is: "browser-tooltip"
})
);
}

/**
* The current active menuitem
* @type {ReturnType<typeof MozMenuItemBaseMixin<Constructor<XULElement>>>["prototype"]}
*/
get activeItem() {
return this.querySelector("[_moz-menuactive='true']");
}

/**
* Updates the menugroup's tooltip text
*/
_updateTooltipText() {
if (this.groupTooltip.state == "closed") return;

if (this.activeItem) {
this.groupTooltip.label = this.activeItem.label;
}
}

connectedCallback() {
this.setAttribute("tooltip", "_child");

this.prepend(this.groupTooltip);

this.groupTooltip.addEventListener(
"popupshowing",
this._updateTooltipText.bind(this)
);
}
}

customElements.define("menugroup", MozMenuGroup);
}

0 comments on commit 98a00cd

Please sign in to comment.