2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import { cloneElement } from '../_util/vnode';
|
|
|
|
function chaining(...fns) {
|
|
|
|
return function(...args) {
|
|
|
|
// eslint-disable-line
|
2018-02-28 15:30:40 +00:00
|
|
|
// eslint-disable-line
|
|
|
|
for (let i = 0; i < fns.length; i++) {
|
|
|
|
if (fns[i] && typeof fns[i] === 'function') {
|
2019-01-12 03:33:27 +00:00
|
|
|
fns[i].apply(this, args);
|
2018-02-28 15:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-02-28 15:30:40 +00:00
|
|
|
}
|
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: {
|
2019-01-12 03:33:27 +00:00
|
|
|
focus() {
|
|
|
|
const ele = this.$refs.ele;
|
|
|
|
ele.focus ? ele.focus() : this.$el.focus();
|
2018-02-27 11:08:49 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
blur() {
|
|
|
|
const ele = this.$refs.ele;
|
|
|
|
ele.blur ? ele.blur() : this.$el.blur();
|
2018-02-27 11:08:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
const { $slots = {}, $listeners = {}, $props = {}, $attrs = {} } = this;
|
|
|
|
const value = $props.value === undefined ? '' : $props.value;
|
|
|
|
const children = $slots.default[0];
|
|
|
|
const { componentOptions = {} } = $slots.default[0];
|
|
|
|
const { listeners = {} } = componentOptions;
|
|
|
|
const newEvent = { ...listeners };
|
2018-02-28 15:30:40 +00:00
|
|
|
|
|
|
|
for (const [eventName, event] of Object.entries($listeners)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
newEvent[eventName] = chaining(event, listeners[eventName]);
|
2018-02-28 15:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-02-27 11:08:49 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|