Skip to content

Commit

Permalink
Merge pull request #453 from yangyy/fix-inputnubmer-paste
Browse files Browse the repository at this point in the history
feat(input): 新增allow-number-paste属性配置 #452
  • Loading branch information
ielgnaw authored Dec 4, 2023
2 parents 9bf7f40 + 728b9ec commit 7203dae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/components/input/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@
| show-word-limit | 是否显示输入字数统计,只在 `type = "text"``type = "textarea"` 时有效 | Boolean | true / false | —— |
| behavior | 简约风格设置(simplicity:简约 normal:正常 type=textarea时不生效) | String | 'normal'/'simplicity' | normal |
| show-clear-only-hover | 是否在只有 hover 的时候才显示 clear 清除按钮 | Boolean | —— | false |
| allow-number-paste | 允许type为number时可粘贴 | Boolean | —— | false |

### 事件 {page=#/input}

Expand Down
13 changes: 10 additions & 3 deletions src/components/input/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ export default {
showClearOnlyHover: {
type: Boolean,
default: false
},
allowNumberPaste: {
type: Boolean,
default: false
}
},
data () {
Expand Down Expand Up @@ -587,11 +591,14 @@ export default {
const keyCode = event.keyCode
const target = event.currentTarget
const value = target.value
const isPaste = (event.ctrlKey || event.metaKey) && keyCode === 86

if (this.inputType === 'number') {
// 键盘按下不允许的按钮
if (this.validKeyCodeList.indexOf(keyCode) < 0
|| event.shiftKey || event.altKey || event.ctrlKey || event.metaKey
// 非粘贴且键盘按下不允许的按钮
if (
!(this.allowNumberPaste && isPaste)
&& (this.validKeyCodeList.indexOf(keyCode) < 0
|| event.shiftKey || event.altKey || event.ctrlKey || event.metaKey)
) {
event.stopPropagation()
event.preventDefault()
Expand Down

0 comments on commit 7203dae

Please sign in to comment.