Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return element from menu.render #6426

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions core/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions core/field_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion core/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class Menu {
*
* @param container Element upon which to append this menu.
*/
NeilFraser marked this conversation as resolved.
Show resolved Hide resolved
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';
Expand Down Expand Up @@ -114,6 +114,7 @@ export class Menu {
element, 'keydown', this, this.handleKeyEvent_);

container.appendChild(element);
return element;
}

/**
Expand Down