Field angle keyboard navigation (#2853)

Field angle keyboard accessibility
This commit is contained in:
Sam El-Husseini
2019-08-20 18:25:15 -07:00
committed by GitHub
parent fe92d56d95
commit 1d4cfb8dfa
2 changed files with 42 additions and 1 deletions

View File

@@ -272,6 +272,14 @@ Blockly.FieldAngle.prototype.onMouseMove = function(e) {
angle -= 360;
}
this.setAngle(angle);
};
/**
* Set the angle value and update the graph.
* @param {number} angle New angle
*/
Blockly.FieldAngle.prototype.setAngle = function(angle) {
// Do rounding.
if (Blockly.FieldAngle.ROUND) {
angle = Math.round(angle / Blockly.FieldAngle.ROUND) *
@@ -281,6 +289,8 @@ Blockly.FieldAngle.prototype.onMouseMove = function(e) {
// Do wrapping.
if (angle > Blockly.FieldAngle.WRAP) {
angle -= 360;
} else if (angle < 0) {
angle += 360;
}
// Update value.
@@ -333,6 +343,37 @@ Blockly.FieldAngle.prototype.updateGraph_ = function() {
this.line_.setAttribute('y2', y2);
};
/**
* Handle key down to the editor.
* @param {!Event} e Keyboard event.
* @protected
* @override
*/
Blockly.FieldAngle.prototype.onHtmlInputKeyDown_ = function(e) {
Blockly.FieldAngle.superClass_.onHtmlInputKeyDown_.call(this, e);
var multiplier;
if (e.keyCode === Blockly.utils.KeyCodes.LEFT) {
// decrement (increment in RTL)
multiplier = this.sourceBlock_.RTL ? 1 : -1;
} else if (e.keyCode === Blockly.utils.KeyCodes.RIGHT) {
// increment (decrement in RTL)
multiplier = this.sourceBlock_.RTL ? -1 : 1;
} else if (e.keyCode === Blockly.utils.KeyCodes.DOWN) {
// decrement
multiplier = -1;
} else if (e.keyCode === Blockly.utils.KeyCodes.UP) {
// increment
multiplier = 1;
}
if (multiplier) {
this.setAngle(Number(this.getValue()) +
(multiplier * Blockly.FieldAngle.ROUND));
e.preventDefault();
e.stopPropagation();
}
};
/**
* Ensure that the input value is a valid angle.
* @param {string|number=} opt_newValue The input value.

View File

@@ -339,7 +339,7 @@ Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() {
/**
* Handle key down to the editor.
* @param {!Event} e Keyboard event.
* @private
* @protected
*/
Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) {
var tabKey = 9, enterKey = 13, escKey = 27;