Merge pull request #2476 from tugcekucukoglu/readonly

Fixed #2469 - InputNumber new readonly attribute
pull/2496/head
Yiğit FINDIKLI 2022-04-25 14:07:46 +03:00 committed by GitHub
commit 1591c3e1e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 2 deletions

View File

@ -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",

View File

@ -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.
*/

View File

@ -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" />
@ -108,6 +108,10 @@ export default {
type: Boolean,
default: true
},
readonly: {
type: Boolean,
default: false
},
style: null,
class: null,
inputStyle: null,
@ -297,6 +301,10 @@ export default {
return null;
},
repeat(event, interval, dir) {
if (this.readonly) {
return;
}
let i = interval || 500;
this.clearTimer();
@ -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;
@ -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);
@ -734,7 +750,9 @@ export default {
return index || 0;
},
onInputClick() {
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))) {

View File

@ -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>