mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 06:03:38 +08:00
Revert "refactor: rc-input-number refactored with baseInput (#42762)"
This reverts commit 3efb68ce6f
.
This commit is contained in:
parent
3efb68ce6f
commit
3eb62fad15
@ -18,7 +18,7 @@ describe('prefix', () => {
|
|||||||
const { container } = render(<InputNumber prefix={<i>123</i>} />);
|
const { container } = render(<InputNumber prefix={<i>123</i>} />);
|
||||||
|
|
||||||
const mockFocus = jest.spyOn(container.querySelector('input')!, 'focus');
|
const mockFocus = jest.spyOn(container.querySelector('input')!, 'focus');
|
||||||
fireEvent.click(container.querySelector('i')!);
|
fireEvent.mouseUp(container.querySelector('i')!);
|
||||||
expect(mockFocus).toHaveBeenCalled();
|
expect(mockFocus).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -5,6 +5,7 @@ import classNames from 'classnames';
|
|||||||
import type { InputNumberProps as RcInputNumberProps } from 'rc-input-number';
|
import type { InputNumberProps as RcInputNumberProps } from 'rc-input-number';
|
||||||
import RcInputNumber from 'rc-input-number';
|
import RcInputNumber from 'rc-input-number';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { cloneElement } from '../_util/reactNode';
|
||||||
import type { InputStatus } from '../_util/statusUtils';
|
import type { InputStatus } from '../_util/statusUtils';
|
||||||
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
|
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
|
||||||
import ConfigProvider, { ConfigContext } from '../config-provider';
|
import ConfigProvider, { ConfigContext } from '../config-provider';
|
||||||
@ -32,6 +33,7 @@ export interface InputNumberProps<T extends ValueType = ValueType>
|
|||||||
const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {
|
const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {
|
||||||
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
||||||
|
|
||||||
|
const [focused, setFocus] = React.useState(false);
|
||||||
const inputRef = React.useRef<HTMLInputElement>(null);
|
const inputRef = React.useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => inputRef.current!);
|
React.useImperativeHandle(ref, () => inputRef.current!);
|
||||||
@ -87,6 +89,9 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props,
|
|||||||
|
|
||||||
const mergedSize = useSize((ctx) => compactSize ?? customizeSize ?? ctx);
|
const mergedSize = useSize((ctx) => compactSize ?? customizeSize ?? ctx);
|
||||||
|
|
||||||
|
const hasPrefix = prefix != null || hasFeedback;
|
||||||
|
const hasAddon = !!(addonBefore || addonAfter);
|
||||||
|
|
||||||
// ===================== Disabled =====================
|
// ===================== Disabled =====================
|
||||||
const disabled = React.useContext(DisabledContext);
|
const disabled = React.useContext(DisabledContext);
|
||||||
const mergedDisabled = customDisabled ?? disabled;
|
const mergedDisabled = customDisabled ?? disabled;
|
||||||
@ -102,73 +107,115 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props,
|
|||||||
getStatusClassNames(prefixCls, mergedStatus),
|
getStatusClassNames(prefixCls, mergedStatus),
|
||||||
compactItemClassnames,
|
compactItemClassnames,
|
||||||
hashId,
|
hashId,
|
||||||
|
className,
|
||||||
|
!hasPrefix && !hasAddon && rootClassName,
|
||||||
);
|
);
|
||||||
const wrapperClassName = `${prefixCls}-group`;
|
|
||||||
|
|
||||||
const element = (
|
let element = (
|
||||||
<RcInputNumber
|
<RcInputNumber
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
disabled={mergedDisabled}
|
disabled={mergedDisabled}
|
||||||
className={classNames(className, rootClassName)}
|
className={inputNumberClass}
|
||||||
upHandler={upIcon}
|
upHandler={upIcon}
|
||||||
downHandler={downIcon}
|
downHandler={downIcon}
|
||||||
prefixCls={prefixCls}
|
prefixCls={prefixCls}
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
controls={controlsTemp}
|
controls={controlsTemp}
|
||||||
prefix={prefix}
|
|
||||||
suffix={hasFeedback && feedbackIcon}
|
|
||||||
addonAfter={
|
|
||||||
addonAfter && (
|
|
||||||
<NoCompactStyle>
|
|
||||||
<NoFormStyle override status>
|
|
||||||
{addonAfter}
|
|
||||||
</NoFormStyle>
|
|
||||||
</NoCompactStyle>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
addonBefore={
|
|
||||||
addonBefore && (
|
|
||||||
<NoCompactStyle>
|
|
||||||
<NoFormStyle override status>
|
|
||||||
{addonBefore}
|
|
||||||
</NoFormStyle>
|
|
||||||
</NoCompactStyle>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
classNames={{
|
|
||||||
input: inputNumberClass,
|
|
||||||
}}
|
|
||||||
classes={{
|
|
||||||
affixWrapper: classNames(
|
|
||||||
getStatusClassNames(`${prefixCls}-affix-wrapper`, mergedStatus, hasFeedback),
|
|
||||||
{
|
|
||||||
[`${prefixCls}-affix-wrapper-sm`]: mergedSize === 'small',
|
|
||||||
[`${prefixCls}-affix-wrapper-lg`]: mergedSize === 'large',
|
|
||||||
[`${prefixCls}-affix-wrapper-rtl`]: direction === 'rtl',
|
|
||||||
[`${prefixCls}-affix-wrapper-borderless`]: !bordered,
|
|
||||||
},
|
|
||||||
hashId,
|
|
||||||
),
|
|
||||||
wrapper: classNames(
|
|
||||||
{
|
|
||||||
[`${wrapperClassName}-rtl`]: direction === 'rtl',
|
|
||||||
},
|
|
||||||
hashId,
|
|
||||||
),
|
|
||||||
group: classNames(
|
|
||||||
{
|
|
||||||
[`${prefixCls}-group-wrapper-sm`]: mergedSize === 'small',
|
|
||||||
[`${prefixCls}-group-wrapper-lg`]: mergedSize === 'large',
|
|
||||||
[`${prefixCls}-group-wrapper-rtl`]: direction === 'rtl',
|
|
||||||
},
|
|
||||||
getStatusClassNames(`${prefixCls}-group-wrapper`, mergedStatus, hasFeedback),
|
|
||||||
hashId,
|
|
||||||
),
|
|
||||||
}}
|
|
||||||
{...others}
|
{...others}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (hasPrefix) {
|
||||||
|
const affixWrapperCls = classNames(
|
||||||
|
`${prefixCls}-affix-wrapper`,
|
||||||
|
getStatusClassNames(`${prefixCls}-affix-wrapper`, mergedStatus, hasFeedback),
|
||||||
|
{
|
||||||
|
[`${prefixCls}-affix-wrapper-focused`]: focused,
|
||||||
|
[`${prefixCls}-affix-wrapper-disabled`]: props.disabled,
|
||||||
|
[`${prefixCls}-affix-wrapper-sm`]: mergedSize === 'small',
|
||||||
|
[`${prefixCls}-affix-wrapper-lg`]: mergedSize === 'large',
|
||||||
|
[`${prefixCls}-affix-wrapper-rtl`]: direction === 'rtl',
|
||||||
|
[`${prefixCls}-affix-wrapper-readonly`]: readOnly,
|
||||||
|
[`${prefixCls}-affix-wrapper-borderless`]: !bordered,
|
||||||
|
},
|
||||||
|
|
||||||
|
// className will go to addon wrapper
|
||||||
|
!hasAddon && className,
|
||||||
|
!hasAddon && rootClassName,
|
||||||
|
hashId,
|
||||||
|
);
|
||||||
|
|
||||||
|
element = (
|
||||||
|
<div
|
||||||
|
className={affixWrapperCls}
|
||||||
|
style={props.style}
|
||||||
|
onMouseUp={() => inputRef.current!.focus()}
|
||||||
|
>
|
||||||
|
{prefix && <span className={`${prefixCls}-prefix`}>{prefix}</span>}
|
||||||
|
{cloneElement(element, {
|
||||||
|
style: null,
|
||||||
|
value: props.value,
|
||||||
|
onFocus: (event: React.FocusEvent<HTMLInputElement>) => {
|
||||||
|
setFocus(true);
|
||||||
|
props.onFocus?.(event);
|
||||||
|
},
|
||||||
|
onBlur: (event: React.FocusEvent<HTMLInputElement>) => {
|
||||||
|
setFocus(false);
|
||||||
|
props.onBlur?.(event);
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
{hasFeedback && <span className={`${prefixCls}-suffix`}>{feedbackIcon}</span>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasAddon) {
|
||||||
|
const wrapperClassName = `${prefixCls}-group`;
|
||||||
|
const addonClassName = `${wrapperClassName}-addon`;
|
||||||
|
const addonBeforeNode = addonBefore ? (
|
||||||
|
<div className={addonClassName}>{addonBefore}</div>
|
||||||
|
) : null;
|
||||||
|
const addonAfterNode = addonAfter ? <div className={addonClassName}>{addonAfter}</div> : null;
|
||||||
|
|
||||||
|
const mergedWrapperClassName = classNames(`${prefixCls}-wrapper`, wrapperClassName, hashId, {
|
||||||
|
[`${wrapperClassName}-rtl`]: direction === 'rtl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const mergedGroupClassName = classNames(
|
||||||
|
`${prefixCls}-group-wrapper`,
|
||||||
|
{
|
||||||
|
[`${prefixCls}-group-wrapper-sm`]: mergedSize === 'small',
|
||||||
|
[`${prefixCls}-group-wrapper-lg`]: mergedSize === 'large',
|
||||||
|
[`${prefixCls}-group-wrapper-rtl`]: direction === 'rtl',
|
||||||
|
},
|
||||||
|
getStatusClassNames(`${prefixCls}-group-wrapper`, mergedStatus, hasFeedback),
|
||||||
|
hashId,
|
||||||
|
className,
|
||||||
|
rootClassName,
|
||||||
|
);
|
||||||
|
element = (
|
||||||
|
<div className={mergedGroupClassName} style={props.style}>
|
||||||
|
<div className={mergedWrapperClassName}>
|
||||||
|
{addonBeforeNode && (
|
||||||
|
<NoCompactStyle>
|
||||||
|
<NoFormStyle status override>
|
||||||
|
{addonBeforeNode}
|
||||||
|
</NoFormStyle>
|
||||||
|
</NoCompactStyle>
|
||||||
|
)}
|
||||||
|
{cloneElement(element, { style: null, disabled: mergedDisabled })}
|
||||||
|
{addonAfterNode && (
|
||||||
|
<NoCompactStyle>
|
||||||
|
<NoFormStyle status override>
|
||||||
|
{addonAfterNode}
|
||||||
|
</NoFormStyle>
|
||||||
|
</NoCompactStyle>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return wrapSSR(element);
|
return wrapSSR(element);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -130,9 +130,9 @@
|
|||||||
"rc-dropdown": "~4.1.0",
|
"rc-dropdown": "~4.1.0",
|
||||||
"rc-field-form": "~1.32.0",
|
"rc-field-form": "~1.32.0",
|
||||||
"rc-image": "~5.17.1",
|
"rc-image": "~5.17.1",
|
||||||
"rc-input": "~1.1.0",
|
"rc-input": "~1.0.4",
|
||||||
"rc-input-number": "~8.0.0",
|
"rc-input-number": "~7.4.0",
|
||||||
"rc-mentions": "~2.4.1",
|
"rc-mentions": "~2.3.0",
|
||||||
"rc-menu": "~9.9.2",
|
"rc-menu": "~9.9.2",
|
||||||
"rc-motion": "^2.7.3",
|
"rc-motion": "^2.7.3",
|
||||||
"rc-notification": "~5.0.4",
|
"rc-notification": "~5.0.4",
|
||||||
@ -148,7 +148,7 @@
|
|||||||
"rc-switch": "~4.1.0",
|
"rc-switch": "~4.1.0",
|
||||||
"rc-table": "~7.32.1",
|
"rc-table": "~7.32.1",
|
||||||
"rc-tabs": "~12.7.0",
|
"rc-tabs": "~12.7.0",
|
||||||
"rc-textarea": "~1.3.0",
|
"rc-textarea": "~1.2.2",
|
||||||
"rc-tooltip": "~6.0.0",
|
"rc-tooltip": "~6.0.0",
|
||||||
"rc-tree": "~5.7.4",
|
"rc-tree": "~5.7.4",
|
||||||
"rc-tree-select": "~5.9.0",
|
"rc-tree-select": "~5.9.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user