From e5b0ac3acd0ef7f45b4e7a027b808c88fff004bf Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 13 Sep 2022 10:45:51 -0700 Subject: [PATCH 1/3] feat: return element from menu.render --- core/contextmenu.ts | 5 ++--- core/field_dropdown.ts | 3 +-- core/menu.ts | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) 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..db6ba94e328 100644 --- a/core/menu.ts +++ b/core/menu.ts @@ -86,7 +86,7 @@ export class Menu { * * @param container Element upon which to append this menu. */ - 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 +114,7 @@ export class Menu { element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); + return element; } /** From 8afe538a5ddd84eb82d2cd9c172382b5face61db Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 13 Sep 2022 10:55:29 -0700 Subject: [PATCH 2/3] chore: format --- core/menu.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/menu.ts b/core/menu.ts index db6ba94e328..2a91f3eb55d 100644 --- a/core/menu.ts +++ b/core/menu.ts @@ -86,7 +86,7 @@ export class Menu { * * @param container Element upon which to append this menu. */ - render(container: Element) : HTMLDivElement { + render(container: Element): HTMLDivElement { const element = (document.createElement('div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; From 877bb606ccb1948ddb6de989383b2699d45493f6 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 13 Sep 2022 13:16:28 -0700 Subject: [PATCH 3/3] chore: add returns annotation --- core/menu.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/menu.ts b/core/menu.ts index 2a91f3eb55d..88a43b9fcdd 100644 --- a/core/menu.ts +++ b/core/menu.ts @@ -85,6 +85,7 @@ 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): HTMLDivElement { const element = (document.createElement('div'));