diff --git a/core/contextmenu.ts b/core/contextmenu.ts index 436f3b1df05..71e4ce8b4db 100644 --- a/core/contextmenu.ts +++ b/core/contextmenu.ts @@ -178,9 +178,8 @@ function createWidget_(menu: Menu) { if (!div) { throw Error('Attempting to create a context menu when widget div is null'); } - menu.render(div); - const menuDom = menu.getElement(); - menuDom?.classList.add('blocklyContextMenu'); + const menuDom = menu.render(div); + menuDom.classList.add('blocklyContextMenu'); // Prevent system context menu when right-clicking a Blockly context menu. browserEvents.conditionalBind( (menuDom as EventTarget), 'contextmenu', null, haltPropagation); diff --git a/core/field_dropdown.ts b/core/field_dropdown.ts index f67db210f83..7c86653b3bc 100644 --- a/core/field_dropdown.ts +++ b/core/field_dropdown.ts @@ -273,8 +273,7 @@ export class FieldDropdown extends Field { // Remove any pre-existing elements in the dropdown. dropDownDiv.clearContent(); // Element gets created in render. - this.menu_!.render(dropDownDiv.getContentDiv()); - const menuElement = this.menu_!.getElement() as Element; + const menuElement = this.menu_!.render(dropDownDiv.getContentDiv()); menuElement.classList.add('blocklyDropdownMenu'); if (this.getConstants()!.FIELD_DROPDOWN_COLOURED_DIV) { diff --git a/core/menu.ts b/core/menu.ts index 722b5114fe3..88a43b9fcdd 100644 --- a/core/menu.ts +++ b/core/menu.ts @@ -85,8 +85,9 @@ export class Menu { * Creates the menu DOM. * * @param container Element upon which to append this menu. + * @returns The menu's root DOM element. */ - render(container: Element) { + render(container: Element): HTMLDivElement { const element = (document.createElement('div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; @@ -114,6 +115,7 @@ export class Menu { element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); + return element; } /**