feat: return element from menu.render (#6426)

* feat: return element from menu.render

* chore: format

* chore: add returns annotation
This commit is contained in:
Rachel Fenichel
2022-09-13 13:29:18 -07:00
committed by GitHub
parent 5f11f3449f
commit e3fa43d861
3 changed files with 6 additions and 6 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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;
}
/**