mirror of
https://github.com/google/blockly.git
synced 2026-01-16 13:27:09 +01:00
Handle blockly actions on the dropdown fields. (#3064)
* Handle blockly actions on the dropdown fields.
This commit is contained in:
@@ -292,9 +292,10 @@ Blockly.Menu.prototype.setHighlighted = function(item) {
|
||||
/**
|
||||
* Highlights the next highlightable item (or the first if nothing is currently
|
||||
* highlighted).
|
||||
* @protected
|
||||
* @package
|
||||
*/
|
||||
Blockly.Menu.prototype.highlightNext = function() {
|
||||
this.unhighlightCurrent();
|
||||
this.highlightHelper(function(index, max) {
|
||||
return (index + 1) % max;
|
||||
}, this.highlightedIndex_);
|
||||
@@ -303,9 +304,10 @@ Blockly.Menu.prototype.highlightNext = function() {
|
||||
/**
|
||||
* Highlights the previous highlightable item (or the last if nothing is
|
||||
* currently highlighted).
|
||||
* @protected
|
||||
* @package
|
||||
*/
|
||||
Blockly.Menu.prototype.highlightPrevious = function() {
|
||||
this.unhighlightCurrent();
|
||||
this.highlightHelper(function(index, max) {
|
||||
index--;
|
||||
return index < 0 ? max - 1 : index;
|
||||
@@ -465,12 +467,10 @@ Blockly.Menu.prototype.handleKeyEventInternal = function(e) {
|
||||
break;
|
||||
|
||||
case Blockly.utils.KeyCodes.UP:
|
||||
this.unhighlightCurrent();
|
||||
this.highlightPrevious();
|
||||
break;
|
||||
|
||||
case Blockly.utils.KeyCodes.DOWN:
|
||||
this.unhighlightCurrent();
|
||||
this.highlightNext();
|
||||
break;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ goog.require('Blockly.Field');
|
||||
goog.require('Blockly.fieldRegistry');
|
||||
goog.require('Blockly.Menu');
|
||||
goog.require('Blockly.MenuItem');
|
||||
goog.require('Blockly.navigation');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.dom');
|
||||
goog.require('Blockly.utils.object');
|
||||
@@ -641,4 +642,24 @@ Blockly.FieldDropdown.validateOptions_ = function(options) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the given action.
|
||||
* This is only triggered when keyboard accessibility mode is enabled.
|
||||
* @param {!Blockly.Action} action The action to be handled.
|
||||
* @return {boolean} True if the field handled the action, false otherwise.
|
||||
* @package
|
||||
*/
|
||||
Blockly.FieldDropdown.prototype.onBlocklyAction = function(action) {
|
||||
if (this.menu_) {
|
||||
if (action === Blockly.navigation.ACTION_PREVIOUS) {
|
||||
this.menu_.highlightPrevious();
|
||||
return true;
|
||||
} else if (action === Blockly.navigation.ACTION_NEXT) {
|
||||
this.menu_.highlightNext();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return Blockly.FieldDropdown.superClass_.onBlocklyAction.call(this, action);
|
||||
};
|
||||
|
||||
Blockly.fieldRegistry.register('field_dropdown', Blockly.FieldDropdown);
|
||||
|
||||
Reference in New Issue
Block a user