75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.default = void 0;
|
||
|
|
||
|
var _UIManager = _interopRequireDefault(require("../../exports/UIManager"));
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
/**
|
||
|
* Copyright (c) Nicolas Gallagher.
|
||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
|
*
|
||
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
|
*
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* This class is responsible for coordinating the "focused"
|
||
|
* state for TextInputs. All calls relating to the keyboard
|
||
|
* should be funneled through here
|
||
|
*/
|
||
|
var TextInputState = {
|
||
|
/**
|
||
|
* Internal state
|
||
|
*/
|
||
|
_currentlyFocusedNode: null,
|
||
|
|
||
|
/**
|
||
|
* Returns the ID of the currently focused text field, if one exists
|
||
|
* If no text field is focused it returns null
|
||
|
*/
|
||
|
currentlyFocusedField: function currentlyFocusedField() {
|
||
|
if (document.activeElement !== this._currentlyFocusedNode) {
|
||
|
this._currentlyFocusedNode = null;
|
||
|
}
|
||
|
|
||
|
return this._currentlyFocusedNode;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @param {Object} TextInputID id of the text field to focus
|
||
|
* Focuses the specified text field
|
||
|
* noop if the text field was already focused
|
||
|
*/
|
||
|
focusTextInput: function focusTextInput(textFieldNode) {
|
||
|
if (textFieldNode !== null) {
|
||
|
this._currentlyFocusedNode = textFieldNode;
|
||
|
|
||
|
if (document.activeElement !== textFieldNode) {
|
||
|
_UIManager.default.focus(textFieldNode);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* @param {Object} textFieldNode id of the text field to focus
|
||
|
* Unfocuses the specified text field
|
||
|
* noop if it wasn't focused
|
||
|
*/
|
||
|
blurTextInput: function blurTextInput(textFieldNode) {
|
||
|
if (textFieldNode !== null) {
|
||
|
this._currentlyFocusedNode = null;
|
||
|
|
||
|
if (document.activeElement === textFieldNode) {
|
||
|
_UIManager.default.blur(textFieldNode);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
var _default = TextInputState;
|
||
|
exports.default = _default;
|
||
|
module.exports = exports.default;
|