ant-design-vue/components/auto-complete/InputElement.jsx

55 lines
1.3 KiB
Vue
Raw Normal View History

2018-03-19 10:16:27 +08:00
2018-02-28 19:07:04 +08:00
import PropTypes from '../_util/vue-types'
2018-03-01 10:21:06 +08:00
import { cloneElement } from '../_util/vnode'
2018-02-28 23:30:40 +08:00
function chaining (...fns) {
return function (...args) { // eslint-disable-line
// eslint-disable-line
for (let i = 0; i < fns.length; i++) {
if (fns[i] && typeof fns[i] === 'function') {
fns[i].apply(this, args)
}
}
}
}
2018-02-27 19:08:49 +08:00
export default {
2018-02-28 19:07:04 +08:00
props: {
value: PropTypes.any,
disabled: PropTypes.bool,
},
2018-02-27 19:08:49 +08:00
methods: {
focus () {
const ele = this.$refs.ele
ele.focus ? ele.focus() : this.$el.focus()
},
blur () {
const ele = this.$refs.ele
ele.blur ? ele.blur() : this.$el.blur()
},
},
render () {
2018-02-28 19:07:04 +08:00
const { $slots = {}, $listeners = {}, $props = {}, $attrs = {}} = this
const value = $props.value === undefined ? '' : $props.value
2018-03-01 10:21:06 +08:00
const children = $slots.default[0]
2018-02-28 23:30:40 +08:00
const { componentOptions = {}} = $slots.default[0]
const { listeners = {}} = componentOptions
const newEvent = { ...listeners }
for (const [eventName, event] of Object.entries($listeners)) {
newEvent[eventName] = chaining(event, listeners[eventName])
}
return cloneElement(children, {
2018-02-27 19:08:49 +08:00
domProps: {
2018-02-28 19:07:04 +08:00
value,
2018-02-27 19:08:49 +08:00
},
2018-02-28 19:07:04 +08:00
props: $props,
2018-02-28 23:30:40 +08:00
on: newEvent,
2018-02-28 19:07:04 +08:00
attrs: { ...$attrs, value },
2018-02-27 19:08:49 +08:00
ref: 'ele',
})
},
}