2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import { cloneElement } from '../_util/vnode';
|
2020-01-18 21:34:23 +08:00
|
|
|
import { getOptionProps, getListeners } from '../_util/props-util';
|
2019-01-12 11:33:27 +08:00
|
|
|
function chaining(...fns) {
|
|
|
|
return function(...args) {
|
|
|
|
// eslint-disable-line
|
2018-02-28 23:30:40 +08:00
|
|
|
// eslint-disable-line
|
|
|
|
for (let i = 0; i < fns.length; i++) {
|
|
|
|
if (fns[i] && typeof fns[i] === 'function') {
|
2019-01-12 11:33:27 +08:00
|
|
|
fns[i].apply(this, args);
|
2018-02-28 23:30:40 +08:00
|
|
|
}
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-02-28 23:30:40 +08:00
|
|
|
}
|
2018-02-27 19:08:49 +08:00
|
|
|
export default {
|
2019-11-20 15:37:47 +08:00
|
|
|
name: 'InputElement',
|
2020-01-18 21:34:23 +08:00
|
|
|
inheritAttrs: false,
|
2018-02-28 19:07:04 +08:00
|
|
|
props: {
|
|
|
|
value: PropTypes.any,
|
|
|
|
disabled: PropTypes.bool,
|
2020-02-07 09:59:40 +08:00
|
|
|
placeholder: PropTypes.string,
|
2018-02-28 19:07:04 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2020-02-07 09:59:40 +08:00
|
|
|
const { $slots = {}, $attrs = {}, placeholder } = this;
|
2020-01-18 21:34:23 +08:00
|
|
|
const listeners = getListeners(this);
|
2019-11-20 15:37:47 +08:00
|
|
|
const props = getOptionProps(this);
|
|
|
|
const value = props.value === undefined ? '' : props.value;
|
2019-01-12 11:33:27 +08:00
|
|
|
const children = $slots.default[0];
|
|
|
|
const { componentOptions = {} } = $slots.default[0];
|
2020-01-18 21:34:23 +08:00
|
|
|
const { listeners: events = {} } = componentOptions;
|
|
|
|
const newEvent = { ...events };
|
2018-02-28 23:30:40 +08:00
|
|
|
|
2020-01-18 21:34:23 +08:00
|
|
|
for (const [eventName, event] of Object.entries(listeners)) {
|
|
|
|
newEvent[eventName] = chaining(event, events[eventName]);
|
2018-02-28 23:30:40 +08:00
|
|
|
}
|
2020-02-07 09:59:40 +08:00
|
|
|
const attrs = { ...$attrs, value };
|
|
|
|
// https://github.com/vueComponent/ant-design-vue/issues/1761
|
|
|
|
delete props.placeholder;
|
|
|
|
if (placeholder) {
|
|
|
|
props.placeholder = placeholder;
|
|
|
|
attrs.placeholder = placeholder;
|
|
|
|
}
|
2018-02-28 23:30:40 +08:00
|
|
|
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
|
|
|
},
|
2019-11-20 15:37:47 +08:00
|
|
|
props,
|
2018-02-28 23:30:40 +08:00
|
|
|
on: newEvent,
|
2020-02-07 09:59:40 +08:00
|
|
|
attrs,
|
2018-02-27 19:08:49 +08:00
|
|
|
ref: 'ele',
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-02-27 19:08:49 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|