MCPcopy Create free account
hub / github.com/microsoft/SandDance / MaskedTextField1

Function MaskedTextField1

docs/app/js/sanddance-app.js:50507–50652  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

50505var MaskedTextField = /** @class */ function(_super) {
50506 (0, _tslib.__extends)(MaskedTextField1, _super);
50507 function MaskedTextField1(props) {
50508 var _this = _super.call(this, props) || this;
50509 _this._textField = _react.createRef();
50510 _this._onFocus = function(event) {
50511 if (_this.props.onFocus) _this.props.onFocus(event);
50512 _this._isFocused = true;
50513 // Move the cursor position to the leftmost unfilled position
50514 for(var i = 0; i < _this._maskCharData.length; i++)if (!_this._maskCharData[i].value) {
50515 _this.setState({
50516 maskCursorPosition: _this._maskCharData[i].displayIndex
50517 });
50518 break;
50519 }
50520 };
50521 _this._onBlur = function(event) {
50522 if (_this.props.onBlur) _this.props.onBlur(event);
50523 _this._isFocused = false;
50524 _this._moveCursorOnMouseUp = true;
50525 };
50526 _this._onMouseDown = function(event) {
50527 if (_this.props.onMouseDown) _this.props.onMouseDown(event);
50528 if (!_this._isFocused) _this._moveCursorOnMouseUp = true;
50529 };
50530 _this._onMouseUp = function(event) {
50531 if (_this.props.onMouseUp) _this.props.onMouseUp(event);
50532 // Move the cursor on mouseUp after focusing the textField
50533 if (_this._moveCursorOnMouseUp) {
50534 _this._moveCursorOnMouseUp = false;
50535 // Move the cursor position to the rightmost unfilled position
50536 for(var i = 0; i < _this._maskCharData.length; i++)if (!_this._maskCharData[i].value) {
50537 _this.setState({
50538 maskCursorPosition: _this._maskCharData[i].displayIndex
50539 });
50540 break;
50541 }
50542 }
50543 };
50544 _this._onInputChange = function(ev, value) {
50545 var textField = _this._textField.current;
50546 if (_this._changeSelectionData === null && textField) _this._changeSelectionData = {
50547 changeType: "default",
50548 selectionStart: textField.selectionStart !== null ? textField.selectionStart : -1,
50549 selectionEnd: textField.selectionEnd !== null ? textField.selectionEnd : -1
50550 };
50551 if (!_this._changeSelectionData) return;
50552 var displayValue = _this.state.displayValue;
50553 // The initial value of cursorPos does not matter
50554 var cursorPos = 0;
50555 var _a = _this._changeSelectionData, changeType = _a.changeType, selectionStart = _a.selectionStart, selectionEnd = _a.selectionEnd;
50556 if (changeType === "textPasted") {
50557 var charsSelected = selectionEnd - selectionStart;
50558 var charCount = value.length + charsSelected - displayValue.length;
50559 var startPos = selectionStart;
50560 var pastedString = value.substr(startPos, charCount);
50561 // Clear any selected characters
50562 if (charsSelected) _this._maskCharData = (0, _inputMask.clearRange)(_this._maskCharData, selectionStart, charsSelected);
50563 cursorPos = (0, _inputMask.insertString)(_this._maskCharData, startPos, pastedString);
50564 } else if (changeType === "delete" || changeType === "backspace") {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected