diff --git a/core/dropdowndiv.ts b/core/dropdowndiv.ts index f5d8076fa..c90661c4e 100644 --- a/core/dropdowndiv.ts +++ b/core/dropdowndiv.ts @@ -113,7 +113,7 @@ export interface PositionMetrics { * @internal */ export function createDom() { - if (div) { + if (document.querySelector('.blocklyDropDownDiv')) { return; // Already created. } div = document.createElement('div'); diff --git a/core/tooltip.ts b/core/tooltip.ts index 51c38e653..0478b91fd 100644 --- a/core/tooltip.ts +++ b/core/tooltip.ts @@ -184,7 +184,7 @@ function getTargetObject( * Create the tooltip div and inject it onto the page. */ export function createDom() { - if (containerDiv) { + if (document.querySelector('.blocklyTooltipDiv')) { return; // Already created. } // Create an HTML container for popup overlays (e.g. editor widgets). diff --git a/core/widgetdiv.ts b/core/widgetdiv.ts index b53f7cd28..52816f363 100644 --- a/core/widgetdiv.ts +++ b/core/widgetdiv.ts @@ -19,6 +19,9 @@ let owner: unknown = null; /** Optional cleanup function set by whichever object uses the widget. */ let dispose: (() => void) | null = null; +/** A class name representing the current owner's workspace container. */ +const containerClassName = 'blocklyWidgetDiv'; + /** A class name representing the current owner's workspace renderer. */ let rendererClassName = ''; @@ -45,18 +48,21 @@ export function getDiv(): HTMLDivElement | null { */ export function testOnly_setDiv(newDiv: HTMLDivElement | null) { containerDiv = newDiv; + if (newDiv === null) { + document.querySelector('.' + containerClassName)?.remove(); + } } /** * Create the widget div and inject it onto the page. */ export function createDom() { - if (containerDiv) { + if (document.querySelector('.' + containerClassName)) { return; // Already created. } containerDiv = document.createElement('div') as HTMLDivElement; - containerDiv.className = 'blocklyWidgetDiv'; + containerDiv.className = containerClassName; const container = common.getParentContainer() || document.body; container.appendChild(containerDiv); }