Skip to content

Commit

Permalink
feat(input): 新增allow-number-paste属性配置 #452
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyy committed Oct 10, 2023
1 parent 4a2d3f2 commit 728b9ec
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 @@ -688,6 +688,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 728b9ec

Please sign in to comment.