You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
7 years ago
|
|
||
7 years ago
|
import PropTypes from '../_util/vue-types'
|
||
7 years ago
|
import { cloneElement } from '../_util/vnode'
|
||
7 years ago
|
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)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
7 years ago
|
export default {
|
||
7 years ago
|
props: {
|
||
|
value: PropTypes.any,
|
||
|
disabled: PropTypes.bool,
|
||
|
},
|
||
7 years ago
|
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 () {
|
||
7 years ago
|
const { $slots = {}, $listeners = {}, $props = {}, $attrs = {}} = this
|
||
|
const value = $props.value === undefined ? '' : $props.value
|
||
7 years ago
|
const children = $slots.default[0]
|
||
7 years ago
|
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, {
|
||
7 years ago
|
domProps: {
|
||
7 years ago
|
value,
|
||
7 years ago
|
},
|
||
7 years ago
|
props: $props,
|
||
7 years ago
|
on: newEvent,
|
||
7 years ago
|
attrs: { ...$attrs, value },
|
||
7 years ago
|
ref: 'ele',
|
||
|
})
|
||
|
},
|
||
|
}
|
||
|
|