mirror of
https://github.com/google/blockly.git
synced 2026-01-10 18:37:09 +01:00
Field angle keyboard navigation (#2853)
Field angle keyboard accessibility
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user