Fixed #2469 - InputNumber new readonly attribute

pull/2476/head
Tuğçe Küçükoğlu 2022-04-21 10:54:13 +03:00
parent 7aab982030
commit 0a1cc7b897
4 changed files with 36 additions and 2 deletions

View File

@ -131,6 +131,12 @@ const InputNumberProps = [
default: "true", default: "true",
description: "Determines whether the input field is empty." 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", name: "inputStyle",
type: "any", type: "any",

View File

@ -133,6 +133,10 @@ export interface InputNumberProps {
* Default value is true. * Default value is true.
*/ */
allowEmpty?: boolean | undefined; allowEmpty?: boolean | undefined;
/**
* When present, it specifies that an input field is read-only.
*/
readonly?: boolean | undefined;
/** /**
* Inline style of the input field. * Inline style of the input field.
*/ */

View File

@ -1,6 +1,6 @@
<template> <template>
<span :class="containerClass" :style="style"> <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"/> @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'"> <span class="p-inputnumber-button-group" v-if="showButtons && buttonLayout === 'stacked'">
<INButton :class="upButtonClass" :icon="incrementButtonIcon" v-on="upButtonListeners" :disabled="$attrs.disabled" /> <INButton :class="upButtonClass" :icon="incrementButtonIcon" v-on="upButtonListeners" :disabled="$attrs.disabled" />
@ -108,6 +108,10 @@ export default {
type: Boolean, type: Boolean,
default: true default: true
}, },
readonly: {
type: Boolean,
default: false
},
style: null, style: null,
class: null, class: null,
inputStyle: null, inputStyle: null,
@ -297,6 +301,10 @@ export default {
return null; return null;
}, },
repeat(event, interval, dir) { repeat(event, interval, dir) {
if (this.readonly) {
return;
}
let i = interval || 500; let i = interval || 500;
this.clearTimer(); this.clearTimer();
@ -379,6 +387,10 @@ export default {
this.isSpecialChar = false; this.isSpecialChar = false;
}, },
onInputKeyDown(event) { onInputKeyDown(event) {
if (this.readonly) {
return;
}
this.lastValue = event.target.value; this.lastValue = event.target.value;
if (event.shiftKey || event.altKey) { if (event.shiftKey || event.altKey) {
this.isSpecialChar = true; this.isSpecialChar = true;
@ -528,6 +540,10 @@ export default {
} }
}, },
onInputKeyPress(event) { onInputKeyPress(event) {
if (this.readonly) {
return;
}
event.preventDefault(); event.preventDefault();
let code = event.which || event.keyCode; let code = event.which || event.keyCode;
let char = String.fromCharCode(code); let char = String.fromCharCode(code);
@ -734,7 +750,9 @@ export default {
return index || 0; return index || 0;
}, },
onInputClick() { onInputClick() {
if (!this.readonly) {
this.initCursor(); this.initCursor();
}
}, },
isNumeralChar(char) { isNumeralChar(char) {
if (char.length === 1 && (this._numeral.test(char) || this._decimal.test(char) || this._group.test(char) || this._minusSign.test(char))) { if (char.length === 1 && (this._numeral.test(char) || this._decimal.test(char) || this._group.test(char) || this._minusSign.test(char))) {

View File

@ -270,6 +270,12 @@ Vertical
<td>allowEmpty</td> <td>allowEmpty</td>
<td>boolean</td> <td>boolean</td>
<td>true</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> <td>Determines whether the input field is empty.</td>
</tr> </tr>
<tr> <tr>