Skip to content

Commit

Permalink
fix(taro-components): 修复 Input 组件 h5 端 事件返回值问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjinjin0731 committed Aug 16, 2018
1 parent 5aaac3a commit 96d4790
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions packages/taro-components/src/components/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,46 @@ function parseType (type, isPassword, confirmType) {
class Input extends Nerv.Component {
constructor () {
super(...arguments)
this.onInput = this.onInput.bind(this)
this.onFocus = this.onFocus.bind(this)
this.onBlur = this.onBlur.bind(this)
}

onInput (e) {
const { onInput, onChange = '' } = this.props
Object.defineProperty(e, 'detail', {
enumerable: true,
value: {
value: e.target.value
}
})
if (onChange) {
onChange && onChange(e)
} else {
onInput && onInput(e)
}
}

onFocus (e) {
const { onFocus } = this.props
Object.defineProperty(e, 'detail', {
enumerable: true,
value: {
value: e.target.value
}
})
onFocus && onFocus(e)
}

onBlur (e) {
const { onBlur } = this.props
Object.defineProperty(e, 'detail', {
enumerable: true,
value: {
value: e.target.value
}
})
onBlur && onBlur(e)
}

render () {
Expand All @@ -36,9 +76,6 @@ class Input extends Nerv.Component {
password,
disabled,
maxlength,
onInput,
onFocus,
onBlur,
confirmType = ''
} = this.props
const cls = classNames('weui-input', className)
Expand All @@ -58,10 +95,10 @@ class Input extends Nerv.Component {
placeholder={placeholder}
disabled={disabled}
max={maxlength}
onChange={onInput}
onInput={onInput}
onFocus={onFocus}
onBlur={onBlur}
onChange={this.onInput}
onInput={this.onInput}
onFocus={this.onFocus}
onBlur={this.onBlur}
type={parseType(type, password, confirmType)}
/>
)
Expand Down

0 comments on commit 96d4790

Please sign in to comment.