diff --git a/packages/blockly/core/field_input.ts b/packages/blockly/core/field_input.ts index 3c9db623cb6..bdf3c189136 100644 --- a/packages/blockly/core/field_input.ts +++ b/packages/blockly/core/field_input.ts @@ -551,6 +551,8 @@ export abstract class FieldInput extends Field< const clickTarget = this.getClickTarget_(); if (!clickTarget) throw new Error('A click target has not been set.'); dom.removeClass(clickTarget, 'blocklyEditing'); + + this.recomputeAriaContext(); } /** diff --git a/packages/blockly/tests/mocha/field_number_test.js b/packages/blockly/tests/mocha/field_number_test.js index 612066b786f..270cac73173 100644 --- a/packages/blockly/tests/mocha/field_number_test.js +++ b/packages/blockly/tests/mocha/field_number_test.js @@ -551,6 +551,24 @@ suite('Number Fields', function () { const updatedLabel = this.focusableElement.getAttribute('aria-label'); assert.isTrue(updatedLabel.includes('1')); }); + test('ARIA label resets after closing editor with invalid input', function () { + this.field.setValue(5); + this.field.showEditor(); + + this.field.htmlInput_.value = 'dog'; + this.field.onHtmlInputChange(null); + assert.equal(this.field.getValue(), 5); + + const labelWhileInvalid = + this.focusableElement.getAttribute('aria-label'); + assert.include(labelWhileInvalid, 'dog'); + + Blockly.WidgetDiv.hideIfOwner(this.field); + + const label = this.focusableElement.getAttribute('aria-label'); + assert.notInclude(label, 'dog'); + assert.include(label, '5'); + }); suite('Full block fields', function () { setup(function () { this.workspace = Blockly.inject('blocklyDiv', {