Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: inputNumber可支持输入框禁用并支持触发点击事件 #513

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/component/input-number.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function handleChange1({ value }) {
| change | 值修改事件 | ` { value }` | - |
| focus | 输入框获取焦点事件 | ` { value, height }` | - |
| blur | 输入框失去焦点事件 | ` { value }` | - |
| clickInput | 禁用input框时点击触发 | 暂无 | - |

## 外部样式类

Expand Down
6 changes: 5 additions & 1 deletion src/pages/inputNumber/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<wd-input-number v-model="value4" @change="handleChange4" disabled />
</demo-block>
<demo-block title="禁用输入框">
<wd-input-number v-model="value10" @change="handleChange4" disable-input />
<wd-input-number v-model="value10" @change="handleChange4" disable-input @clickInput="handleClickInput" />
</demo-block>
<demo-block title="无输入框">
<view class="flex">
Expand Down Expand Up @@ -76,6 +76,10 @@ function handleChange8({ value }: any) {
function handleChange9({ value }: any) {
console.log(value)
}

function handleClickInput() {
console.log('点击了输入框')
}
</script>
<style lang="scss" scoped>
.flex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
position: relative;
display: inline-block;
vertical-align: middle;
line-height: 2;
}

@include e(input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
</view>
<view v-if="!withoutInput" class="wd-input-number__inner" @click.stop="">
<input
v-if="!disableInput"
class="wd-input-number__input"
:style="`${inputWidth ? 'width: ' + inputWidth : ''}`"
type="digit"
:disabled="disabled || disableInput"
:disabled="disabled"
v-model="inputValue"
:placeholder="placeholder"
@input="handleInput"
@focus="handleFocus"
@blur="handleBlur"
/>
<view @click="handleClickInput" v-else :style="`${inputWidth ? 'width: ' + inputWidth : ''}`" class="wd-input-number__input">
{{ inputValue }}
</view>
<view class="wd-input-number__input-border"></view>
</view>
<view :class="`wd-input-number__action ${maxDisabled || disablePlus ? 'is-disabled' : ''}`" @click="add">
Expand All @@ -40,7 +44,7 @@ import { debounce, isDef, isEqual } from '../common/util'
import { inputNumberProps } from './types'

const props = defineProps(inputNumberProps)
const emit = defineEmits(['focus', 'blur', 'change', 'update:modelValue'])
const emit = defineEmits(['focus', 'blur', 'change', 'update:modelValue', 'clickInput'])

const minDisabled = ref<boolean>(false)
const maxDisabled = ref<boolean>(false)
Expand Down Expand Up @@ -160,7 +164,9 @@ function handleInput(event: any) {
function handleFocus(event: any) {
emit('focus', event.detail)
}

function handleClickInput(event: any) {
emit('clickInput')
}
function handleBlur() {
const value = formatValue(inputValue.value)
if (!isEqual(inputValue.value, value)) {
Expand Down