Improve screenreader focus behaviour when copying or moving blocks to a marked field.

This commit is contained in:
Sean Lip
2016-08-01 18:00:53 -07:00
parent 51a6bd3873
commit 2312a2d716
3 changed files with 16 additions and 6 deletions

View File

@@ -46,6 +46,13 @@ blocklyApp.ClipboardService = ng.core
this.areConnectionsCompatible_(connection, superiorConnection) ||
this.areConnectionsCompatible_(connection, nextConnection));
},
getMarkedConnectionBlock: function() {
if (!this.markedConnection_) {
return null;
} else {
return this.markedConnection_.getSourceBlock();
}
},
isMovableToMarkedConnection: function(block) {
// It should not be possible to move any ancestor of the block containing
// the marked spot to the marked spot.
@@ -53,7 +60,7 @@ blocklyApp.ClipboardService = ng.core
return false;
}
var markedSpotAncestorBlock = this.markedConnection_.getSourceBlock();
var markedSpotAncestorBlock = this.getMarkedConnectionBlock();
while (markedSpotAncestorBlock) {
if (markedSpotAncestorBlock.id == block.id) {
return false;

View File

@@ -149,11 +149,15 @@ blocklyApp.ToolboxTreeComponent = ng.core
this.clipboardService.copy(this.block, true);
},
copyToMarkedSpot: function() {
// This involves two steps:
// This involves the following steps:
// - Clear screenreader focus on the destination tree.
// - Put the block on the destination tree.
// - Change the current tree-level focus to the destination tree, and the
// screenreader focus for the destination tree to the block just moved.
var blockDescription = this.getBlockDescription();
var destinationTreeId = this.treeService.getTreeIdForBlock(
this.clipboardService.getMarkedConnectionBlock().id);
this.treeService.clearActiveDesc(destinationTreeId);
var newBlockId = this.clipboardService.pasteToMarkedConnection(
this.block);
@@ -161,7 +165,6 @@ blocklyApp.ToolboxTreeComponent = ng.core
// Invoke a digest cycle, so that the DOM settles.
var that = this;
setTimeout(function() {
var destinationTreeId = that.treeService.getTreeIdForBlock(newBlockId);
document.getElementById(destinationTreeId).focus();
that.treeService.setActiveDesc(
newBlockId + 'blockRoot', destinationTreeId);

View File

@@ -203,6 +203,9 @@ blocklyApp.WorkspaceTreeComponent = ng.core
// - Change the current tree-level focus to the destination tree, and the
// screenreader focus for the destination tree to the block just moved.
var blockDescription = this.getBlockDescription();
var destinationTreeId = this.treeService.getTreeIdForBlock(
this.clipboardService.getMarkedConnectionBlock().id);
this.treeService.clearActiveDesc(destinationTreeId);
var newBlockId = this.clipboardService.pasteToMarkedConnection(
this.block);
@@ -214,9 +217,6 @@ blocklyApp.WorkspaceTreeComponent = ng.core
// Invoke a digest cycle, so that the DOM settles.
setTimeout(function() {
var destinationTreeId = that.treeService.getTreeIdForBlock(newBlockId);
that.treeService.clearActiveDesc(destinationTreeId);
document.getElementById(destinationTreeId).focus();
that.treeService.setActiveDesc(
newBlockId + 'blockRoot', destinationTreeId);