MCPcopy Create free account
hub / github.com/UI5/webcomponents / _onkeydown

Method _onkeydown

packages/main/src/StepInput.ts:696–747  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

694 }
695
696 _onkeydown(e: KeyboardEvent) {
697 let preventDefault = true;
698 if (this.disabled || this.readonly) {
699 return;
700 }
701
702 if (isEnter(e)) {
703 this._onInputChange();
704 return;
705 }
706
707 if (isUp(e)) {
708 // step up
709 this._modifyValue(this.step);
710 } else if (isDown(e)) {
711 // step down
712 this._modifyValue(-this.step);
713 } else if (isEscape(e)) {
714 // return previous value
715 if (this._previousValue === undefined) {
716 this._previousValue = this.value;
717 }
718 this.value = this._previousValue;
719 this.input.value = this.value.toFixed(this.valuePrecision);
720 } else if (this.max !== undefined && (isPageUpShift(e) || isUpShiftCtrl(e))) {
721 // step to max
722 this._modifyValue(this.max - this.value);
723 } else if (this.min !== undefined && (isPageDownShift(e) || isDownShiftCtrl(e))) {
724 // step to min
725 this._modifyValue(this.min - this.value);
726 } else if (!isUpCtrl(e) && !isDownCtrl(e) && !isUpShift(e) && !isDownShift(e)) {
727 preventDefault = false;
728 }
729
730 if (e.key && e.key.length !== 1) {
731 return;
732 }
733
734 const caretPosition = this._getCaretPosition();
735 const inputValue = this.innerInput.value;
736 const typedValue = this._getValueOnkeyDown(e, inputValue, caretPosition!);
737 const parsedValue = this._parseNumber(typedValue);
738 const isValidTypedValue = this._isInputValueValid(typedValue, parsedValue);
739
740 if (preventDefault || !isValidTypedValue) {
741 e.preventDefault();
742 }
743
744 if (caretPosition === 0 && isMinus(e)) {
745 this._updateValueAndValidate(parsedValue);
746 }
747 }
748
749 _getCaretPosition() {
750 return this.input.getDomRef()!.querySelector("input")!.selectionStart;

Callers

nothing calls this directly

Calls 15

_onInputChangeMethod · 0.95
_modifyValueMethod · 0.95
_getCaretPositionMethod · 0.95
_getValueOnkeyDownMethod · 0.95
_parseNumberMethod · 0.95
_isInputValueValidMethod · 0.95
isEnterFunction · 0.85
isUpFunction · 0.85
isDownFunction · 0.85
isEscapeFunction · 0.85
isPageUpShiftFunction · 0.85

Tested by

no test coverage detected