Skip to content

Commit

Permalink
Fixed #2469 - InputNumber new readonly attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Apr 21, 2022
1 parent 7aab982 commit 0a1cc7b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api-generator/components/inputnumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ const InputNumberProps = [
default: "true",
description: "Determines whether the input field is empty."
},
{
name: "readonly",
type: "boolean",
default: "false",
description: "When present, it specifies that an input field is read-only."
},
{
name: "inputStyle",
type: "any",
Expand Down
4 changes: 4 additions & 0 deletions src/components/inputnumber/InputNumber.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export interface InputNumberProps {
* Default value is true.
*/
allowEmpty?: boolean | undefined;
/**
* When present, it specifies that an input field is read-only.
*/
readonly?: boolean | undefined;
/**
* Inline style of the input field.
*/
Expand Down
22 changes: 20 additions & 2 deletions src/components/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<span :class="containerClass" :style="style">
<INInputText ref="input" :class="['p-inputnumber-input', inputClass]" :style="inputStyle" :value="formattedValue" v-bind="$attrs" :aria-valumin="min" :aria-valuemax="max"
<INInputText ref="input" :class="['p-inputnumber-input', inputClass]" :style="inputStyle" :value="formattedValue" v-bind="$attrs" :aria-valumin="min" :aria-valuemax="max" :readonly="readonly"
@input="onUserInput" @keydown="onInputKeyDown" @keypress="onInputKeyPress" @paste="onPaste" @click="onInputClick" @focus="onInputFocus" @blur="onInputBlur"/>
<span class="p-inputnumber-button-group" v-if="showButtons && buttonLayout === 'stacked'">
<INButton :class="upButtonClass" :icon="incrementButtonIcon" v-on="upButtonListeners" :disabled="$attrs.disabled" />
Expand Down Expand Up @@ -108,6 +108,10 @@ export default {
type: Boolean,
default: true
},
readonly: {
type: Boolean,
default: false
},
style: null,
class: null,
inputStyle: null,
Expand Down Expand Up @@ -297,6 +301,10 @@ export default {
return null;
},
repeat(event, interval, dir) {
if (this.readonly) {
return;
}
let i = interval || 500;
this.clearTimer();
Expand Down Expand Up @@ -379,6 +387,10 @@ export default {
this.isSpecialChar = false;
},
onInputKeyDown(event) {
if (this.readonly) {
return;
}
this.lastValue = event.target.value;
if (event.shiftKey || event.altKey) {
this.isSpecialChar = true;
Expand Down Expand Up @@ -528,6 +540,10 @@ export default {
}
},
onInputKeyPress(event) {
if (this.readonly) {
return;
}
event.preventDefault();
let code = event.which || event.keyCode;
let char = String.fromCharCode(code);
Expand Down Expand Up @@ -734,7 +750,9 @@ export default {
return index || 0;
},
onInputClick() {
this.initCursor();
if (!this.readonly) {
this.initCursor();
}
},
isNumeralChar(char) {
if (char.length === 1 && (this._numeral.test(char) || this._decimal.test(char) || this._group.test(char) || this._minusSign.test(char))) {
Expand Down
6 changes: 6 additions & 0 deletions src/views/inputnumber/InputNumberDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ Vertical
<td>allowEmpty</td>
<td>boolean</td>
<td>true</td>
<td>When present, it specifies that an input field is read-only.</td>
</tr>
<tr>
<td>readonly</td>
<td>boolean</td>
<td>false</td>
<td>Determines whether the input field is empty.</td>
</tr>
<tr>
Expand Down

0 comments on commit 0a1cc7b

Please sign in to comment.