Update toolbox drag target when visibility changes (#4919)

This commit is contained in:
Monica Kozbial
2021-06-17 15:17:36 -07:00
committed by GitHub
parent ad7a40dac4
commit 7d45b531ac

View File

@@ -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<!Blockly.IToolboxItem>}
@@ -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();
};
/**