From cc6252cc0028973516f2a7faf67cd67bce35d4ff Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Thu, 14 Jul 2016 15:52:58 -0700 Subject: [PATCH] Set activedescendant correctly on workspace trees. --- accessible/workspace-tree.component.js | 20 ++++++++++++-------- accessible/workspace.component.js | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/accessible/workspace-tree.component.js b/accessible/workspace-tree.component.js index 5c7f4dc5f..83dda119b 100644 --- a/accessible/workspace-tree.component.js +++ b/accessible/workspace-tree.component.js @@ -266,14 +266,18 @@ blocklyApp.WorkspaceTreeComponent = ng.core }, ngAfterViewInit: function() { // If this is a top-level tree in the workspace, set its id and active - // descendant. - if (this.tree && this.isTopLevel && !this.tree.id) { - this.tree.id = this.utilsService.generateUniqueId(); - } - if (this.tree && this.isTopLevel && - !this.treeService.getActiveDescId(this.tree.id)) { - this.treeService.setActiveDesc(this.idMap['blockRoot'], this.tree.id); - } + // descendant. (Note that a timeout is needed here in order to trigger + // Angular change detection.) + var that = this; + setTimeout(function() { + if (that.tree && that.isTopLevel && !that.tree.id) { + that.tree.id = that.utilsService.generateUniqueId(); + } + if (that.tree && that.isTopLevel && + !that.treeService.getActiveDescId(that.tree.id)) { + that.treeService.setActiveDesc(that.idMap['blockRoot'], that.tree.id); + } + }); }, generateAriaLabelledByAttr: function(mainLabel, secondLabel, isDisabled) { return this.utilsService.generateAriaLabelledByAttr( diff --git a/accessible/workspace.component.js b/accessible/workspace.component.js index 1efc6ee7a..42eb84d4e 100644 --- a/accessible/workspace.component.js +++ b/accessible/workspace.component.js @@ -75,8 +75,8 @@ blocklyApp.WorkspaceComponent = ng.core clearWorkspace: function() { this.workspace.clear(); }, - getActiveDescId: function(tree) { - return this.treeService.getActiveDescId(tree.id); + getActiveDescId: function(treeId) { + return this.treeService.getActiveDescId(treeId); }, onWorkspaceToolbarKeypress: function(e) { this.treeService.onWorkspaceToolbarKeypress(