From 7d45b531ac778d26ccb21f3b1b2fa3ef717209f6 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 17 Jun 2021 15:17:36 -0700 Subject: [PATCH] Update toolbox drag target when visibility changes (#4919) --- core/toolbox/toolbox.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/toolbox/toolbox.js b/core/toolbox/toolbox.js index ff039e1dd..c3e32b94f 100644 --- a/core/toolbox/toolbox.js +++ b/core/toolbox/toolbox.js @@ -99,6 +99,13 @@ Blockly.Toolbox = function(workspace) { */ this.contentsDiv_ = null; + /** + * Whether the Toolbox is visible. + * @type {boolean} + * @protected + */ + this.isVisible_ = false; + /** * The list of items in the toolbox. * @type {!Array} @@ -193,6 +200,7 @@ Blockly.Toolbox.prototype.init = function() { this.HtmlDiv = this.createDom_(this.workspace_); Blockly.utils.dom.insertAfter(this.flyout_.createDom('svg'), svg); + this.setVisible(true); this.flyout_.init(workspace); this.render(this.toolboxDef_); @@ -514,7 +522,7 @@ Blockly.Toolbox.prototype.removeStyle = function(style) { * target area should be ignored. */ Blockly.Toolbox.prototype.getClientRect = function() { - if (!this.HtmlDiv) { + if (!this.HtmlDiv || !this.isVisible_) { return null; } @@ -810,7 +818,15 @@ Blockly.Toolbox.prototype.refreshSelection = function() { * @public */ Blockly.Toolbox.prototype.setVisible = function(isVisible) { + if (this.isVisible_ === isVisible) { + return; + } + this.HtmlDiv.style.display = isVisible ? 'block' : 'none'; + this.isVisible_ = isVisible; + // Invisible toolbox is ignored as drag targets and must have the drag target + // updated. + this.workspace_.recordDragTargets(); }; /**