From cb8ed73c48bc3187c001d2ce9f75bc77a7a2257c Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Thu, 15 Jun 2023 15:31:40 -0700 Subject: [PATCH] fix: update disabled status after rendering (#7172) * fix: update disabled status after rendering * fix: add test for json disabled --- core/block_svg.ts | 5 +++++ tests/mocha/block_test.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/core/block_svg.ts b/core/block_svg.ts index f24e0e085..ed942b1aa 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -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_(); } diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 24248175e..4da49a08c 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -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' + ); + }); }); });