fix: update disabled status after rendering (#7172)

* fix: update disabled status after rendering

* fix: add test for json disabled
This commit is contained in:
Maribeth Bottorff
2023-06-15 15:31:40 -07:00
committed by GitHub
parent 817ffab754
commit cb8ed73c48
2 changed files with 21 additions and 0 deletions

View File

@@ -1578,6 +1578,11 @@ export class BlockSvg
this.rendered = true;
dom.startTextWidthCache();
if (!this.isEnabled()) {
// Apply disabled styles if needed.
this.updateDisabled();
}
if (this.isCollapsed()) {
this.updateCollapsed_();
}

View File

@@ -2144,6 +2144,22 @@ suite('Blocks', function () {
// Child blocks should stay disabled if they have been set.
chai.assert.isTrue(blockB.disabled);
});
test('Disabled blocks from JSON should have proper disabled status', function () {
const blockJson = {
'type': 'controls_if',
'enabled': false,
};
Blockly.serialization.blocks.append(blockJson, this.workspace);
const block = this.workspace.getTopBlocks(false)[0];
chai.assert.isTrue(
block.visuallyDisabled,
'block should have visuallyDisabled set because it is disabled'
);
chai.assert.isFalse(
block.isEnabled(),
'block should be marked disabled because enabled json property was set to false'
);
});
});
});