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

55 lines
1.3 KiB
Vue
Raw Normal View History

2018-03-19 02:16:27 +00:00
2018-02-28 11:07:04 +00:00
import PropTypes from '../_util/vue-types'
2018-03-01 02:21:06 +00:00
import { cloneElement } from '../_util/vnode'
2018-02-28 15:30:40 +00: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 11:08:49 +00:00
export default {
2018-02-28 11:07:04 +00:00
props: {
value: PropTypes.any,
disabled: PropTypes.bool,
},
2018-02-27 11:08:49 +00: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 11:07:04 +00:00
const { $slots = {}, $listeners = {}, $props = {}, $attrs = {}} = this
const value = $props.value === undefined ? '' : $props.value
2018-03-01 02:21:06 +00:00
const children = $slots.default[0]
2018-02-28 15:30:40 +00: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 11:08:49 +00:00
domProps: {
2018-02-28 11:07:04 +00:00
value,
2018-02-27 11:08:49 +00:00
},
2018-02-28 11:07:04 +00:00
props: $props,
2018-02-28 15:30:40 +00:00
on: newEvent,
2018-02-28 11:07:04 +00:00
attrs: { ...$attrs, value },
2018-02-27 11:08:49 +00:00
ref: 'ele',
})
},
}