Skip to content

Commit 93bde3f

Browse files
committed
feat: update inputnumber
1 parent a0c08a5 commit 93bde3f

File tree

7 files changed

+174
-141
lines changed

7 files changed

+174
-141
lines changed

antdv-demo

components/input-number/index.jsx

+30-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { inject } from 'vue';
12
import PropTypes from '../_util/vue-types';
2-
import { initDefaultProps, getOptionProps, getListeners } from '../_util/props-util';
3+
import { initDefaultProps, getOptionProps } from '../_util/props-util';
34
import classNames from 'classnames';
45
import UpOutlined from '@ant-design/icons-vue/UpOutlined';
56
import DownOutlined from '@ant-design/icons-vue/DownOutlined';
67
import VcInputNumber from '../vc-input-number/src';
78
import { ConfigConsumerProps } from '../config-provider';
8-
import Base from '../base';
99

1010
export const InputNumberProps = {
1111
prefixCls: PropTypes.string,
@@ -29,56 +29,59 @@ export const InputNumberProps = {
2929

3030
const InputNumber = {
3131
name: 'AInputNumber',
32-
model: {
33-
prop: 'value',
34-
event: 'change',
35-
},
32+
inheritAttrs: false,
3633
props: initDefaultProps(InputNumberProps, {
3734
step: 1,
3835
}),
39-
inject: {
40-
configProvider: { default: () => ConfigConsumerProps },
36+
setup() {
37+
return {
38+
configProvider: inject('configProvider', ConfigConsumerProps),
39+
};
4140
},
4241
methods: {
42+
saveInputNumber(inputNumberRef) {
43+
this.inputNumberRef = inputNumberRef;
44+
},
4345
focus() {
44-
this.$refs.inputNumberRef.focus();
46+
this.inputNumberRef.focus();
4547
},
4648
blur() {
47-
this.$refs.inputNumberRef.blur();
49+
this.inputNumberRef.blur();
4850
},
4951
},
5052

5153
render() {
52-
const { prefixCls: customizePrefixCls, size, ...others } = getOptionProps(this);
54+
const { prefixCls: customizePrefixCls, size, class: className, ...others } = {
55+
...getOptionProps(this),
56+
...this.$attrs,
57+
};
5358
const getPrefixCls = this.configProvider.getPrefixCls;
5459
const prefixCls = getPrefixCls('input-number', customizePrefixCls);
5560

56-
const inputNumberClass = classNames({
57-
[`${prefixCls}-lg`]: size === 'large',
58-
[`${prefixCls}-sm`]: size === 'small',
59-
});
61+
const inputNumberClass = classNames(
62+
{
63+
[`${prefixCls}-lg`]: size === 'large',
64+
[`${prefixCls}-sm`]: size === 'small',
65+
},
66+
className,
67+
);
6068
const upIcon = <UpOutlined class={`${prefixCls}-handler-up-inner`} />;
6169
const downIcon = <DownOutlined class={`${prefixCls}-handler-down-inner`} />;
6270

6371
const vcInputNumberprops = {
64-
props: {
65-
prefixCls,
66-
upHandler: upIcon,
67-
downHandler: downIcon,
68-
...others,
69-
},
72+
prefixCls,
73+
upHandler: upIcon,
74+
downHandler: downIcon,
75+
...others,
7076
class: inputNumberClass,
71-
ref: 'inputNumberRef',
72-
on: getListeners(this),
7377
};
74-
return <VcInputNumber {...vcInputNumberprops} />;
78+
return <VcInputNumber {...vcInputNumberprops} ref={this.saveInputNumber} />;
7579
},
7680
};
7781

7882
/* istanbul ignore next */
79-
InputNumber.install = function(Vue) {
80-
Vue.use(Base);
81-
Vue.component(InputNumber.name, InputNumber);
83+
InputNumber.install = function(app) {
84+
app.component(InputNumber.name, InputNumber);
8285
};
8386

8487
export default InputNumber;

components/vc-input-number/src/InputHandler.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import PropTypes from '../../_util/vue-types';
22
import Touchable from '../../vc-m-feedback';
3-
import { getListeners } from '../../_util/props-util';
3+
import { getSlot } from '../../_util/props-util';
44

55
const InputHandler = {
66
name: 'InputHandler',
7+
inheritAttrs: false,
78
props: {
89
prefixCls: PropTypes.string,
910
disabled: PropTypes.bool,
1011
},
1112
render() {
1213
const { prefixCls, disabled } = this.$props;
1314
const touchableProps = {
14-
props: {
15-
disabled,
16-
activeClassName: `${prefixCls}-handler-active`,
17-
},
18-
on: getListeners(this),
15+
disabled,
16+
activeClassName: `${prefixCls}-handler-active`,
1917
};
2018
return (
2119
<Touchable {...touchableProps}>
22-
<span>{this.$slots.default}</span>
20+
<span {...this.$attrs}>{getSlot(this)}</span>
2321
</Touchable>
2422
);
2523
},

0 commit comments

Comments
 (0)