mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 20:19:44 +08:00
refactor(input-number): rewrite with hook (#23461)
This commit is contained in:
parent
3e22b505a3
commit
4a3e01ff0b
@ -6,7 +6,7 @@ import mountTest from '../../../tests/shared/mountTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
|
||||
describe('InputNumber', () => {
|
||||
focusTest(InputNumber);
|
||||
focusTest(InputNumber, true);
|
||||
mountTest(InputNumber);
|
||||
rtlTest(InputNumber);
|
||||
|
||||
|
@ -35,27 +35,9 @@ export interface InputNumberProps
|
||||
onPressEnter?: React.KeyboardEventHandler<HTMLInputElement>;
|
||||
}
|
||||
|
||||
export default class InputNumber extends React.Component<InputNumberProps, any> {
|
||||
static defaultProps = {
|
||||
step: 1,
|
||||
};
|
||||
|
||||
private inputNumberRef: any;
|
||||
|
||||
saveInputNumber = (inputNumberRef: any) => {
|
||||
this.inputNumberRef = inputNumberRef;
|
||||
};
|
||||
|
||||
focus() {
|
||||
this.inputNumberRef.focus();
|
||||
}
|
||||
|
||||
blur() {
|
||||
this.inputNumberRef.blur();
|
||||
}
|
||||
|
||||
renderInputNumber = ({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
||||
const { className, size: customizeSize, prefixCls: customizePrefixCls, ...others } = this.props;
|
||||
const InputNumber = React.forwardRef<unknown, InputNumberProps>((props, ref) => {
|
||||
const renderInputNumber = ({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
||||
const { className, size: customizeSize, prefixCls: customizePrefixCls, ...others } = props;
|
||||
const prefixCls = getPrefixCls('input-number', customizePrefixCls);
|
||||
const upIcon = <UpOutlined className={`${prefixCls}-handler-up-inner`} />;
|
||||
const downIcon = <DownOutlined className={`${prefixCls}-handler-down-inner`} />;
|
||||
@ -75,7 +57,7 @@ export default class InputNumber extends React.Component<InputNumberProps, any>
|
||||
|
||||
return (
|
||||
<RcInputNumber
|
||||
ref={this.saveInputNumber}
|
||||
ref={ref}
|
||||
className={inputNumberClass}
|
||||
upHandler={upIcon}
|
||||
downHandler={downIcon}
|
||||
@ -88,7 +70,11 @@ export default class InputNumber extends React.Component<InputNumberProps, any>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
return <ConfigConsumer>{this.renderInputNumber}</ConfigConsumer>;
|
||||
}
|
||||
}
|
||||
return <ConfigConsumer>{renderInputNumber}</ConfigConsumer>;
|
||||
});
|
||||
|
||||
InputNumber.defaultProps = {
|
||||
step: 1,
|
||||
};
|
||||
|
||||
export default InputNumber;
|
||||
|
Loading…
Reference in New Issue
Block a user