Skip to content

Commit

Permalink
Fixed #2238 - [Bug]: ReadOnly InputNumber is editable
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 7, 2021
1 parent 464f82a commit 94cb5fb
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/components/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,39 +296,39 @@ export class InputNumber extends Component {
}

onUpButtonMouseDown(event) {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.inputRef.current.focus();
this.repeat(event, null, 1);
event.preventDefault();
}
}

onUpButtonMouseUp() {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.clearTimer();
}
}

onUpButtonMouseLeave() {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.clearTimer();
}
}

onUpButtonKeyUp() {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.clearTimer();
}
}

onUpButtonKeyDown(event) {
if (event.keyCode === 32 || event.keyCode === 13) {
if (!this.props.disabled && !this.props.readOnly && (event.keyCode === 32 || event.keyCode === 13)) {
this.repeat(event, null, 1);
}
}

onDownButtonMouseDown(event) {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.inputRef.current.focus();
this.repeat(event, null, -1);

Expand All @@ -337,37 +337,45 @@ export class InputNumber extends Component {
}

onDownButtonMouseUp() {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.clearTimer();
}
}

onDownButtonMouseLeave() {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.clearTimer();
}
}

onDownButtonKeyUp() {
if (!this.props.disabled) {
if (!this.props.disabled && !this.props.readOnly) {
this.clearTimer();
}
}

onDownButtonKeyDown(event) {
if (event.keyCode === 32 || event.keyCode === 13) {
if (!this.props.disabled && !this.props.readOnly && (event.keyCode === 32 || event.keyCode === 13)) {
this.repeat(event, null, -1);
}
}

onInput(event) {
if (this.props.disabled || this.props.readOnly) {
return;
}

if (this.isSpecialChar) {
event.target.value = this.lastValue;
}
this.isSpecialChar = false;
}

onInputKeyDown(event) {
if (this.props.disabled || this.props.readOnly) {
return;
}

this.lastValue = event.target.value;
if (event.shiftKey || event.altKey) {
this.isSpecialChar = true;
Expand Down Expand Up @@ -521,6 +529,10 @@ export class InputNumber extends Component {
}

onInputKeyPress(event) {
if (this.props.disabled || this.props.readOnly) {
return;
}

let code = event.which || event.keyCode;
let char = String.fromCharCode(code);
const isDecimalSign = this.isDecimalSign(char);
Expand All @@ -535,6 +547,11 @@ export class InputNumber extends Component {

onPaste(event) {
event.preventDefault();

if (this.props.disabled || this.props.readOnly) {
return;
}

let data = (event.clipboardData || window['clipboardData']).getData('Text');
if (data) {
let filteredData = this.parseValue(data);
Expand Down

0 comments on commit 94cb5fb

Please sign in to comment.