refactor: refactor InputNumber code (#49428)

This commit is contained in:
lijianan 2024-06-15 19:44:35 +08:00 committed by GitHub
parent 6db789f772
commit 7769a40c72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 22 deletions

View File

@ -124,6 +124,19 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props,
);
const wrapperClassName = `${prefixCls}-group`;
const getAddon = (addon: React.ReactNode): React.ReactNode => {
if (!addon) {
return null;
}
return (
<NoCompactStyle>
<NoFormStyle override status>
{addon}
</NoFormStyle>
</NoCompactStyle>
);
};
const element = (
<RcInputNumber
ref={inputRef}
@ -136,31 +149,14 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props,
controls={controlsTemp}
prefix={prefix}
suffix={suffixNode}
addonAfter={
addonAfter && (
<NoCompactStyle>
<NoFormStyle override status>
{addonAfter}
</NoFormStyle>
</NoCompactStyle>
)
}
addonBefore={
addonBefore && (
<NoCompactStyle>
<NoFormStyle override status>
{addonBefore}
</NoFormStyle>
</NoCompactStyle>
)
}
addonBefore={getAddon(addonBefore)}
addonAfter={getAddon(addonAfter)}
classNames={{
input: inputNumberClass,
variant: classNames(
{
[`${prefixCls}-${variant}`]: enableVariantCls,
},
getStatusClassNames(prefixCls, mergedStatus, hasFeedback),
),
affixWrapper: classNames(

View File

@ -171,7 +171,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
</>
);
const getAddon = (addon: React.ReactNode) =>
const getAddon = (addon: React.ReactNode): React.ReactNode =>
addon && (
<NoCompactStyle>
<NoFormStyle override status>

View File

@ -26,4 +26,5 @@ Input.Search = Search;
Input.TextArea = TextArea;
Input.Password = Password;
Input.OTP = OTP;
export default Input;

View File

@ -101,7 +101,7 @@ const InternalPopover = React.forwardRef<TooltipRef, PopoverProps>((props, ref)
data-popover-inject
>
{cloneElement(children, {
onKeyDown: (e: React.KeyboardEvent<any>) => {
onKeyDown: (e: React.KeyboardEvent<HTMLDivElement>) => {
if (React.isValidElement(children)) {
children?.props.onKeyDown?.(e);
}

View File

@ -31,7 +31,7 @@ export default function rootPropsTest(
const componentNames = Array.isArray(component) ? component : [component];
const [componentName, subComponentName] = componentNames;
const Component = require(`../../components/${componentName}`).default as any;
const Component = require(`../../components/${componentName}`).default;
const name = options?.name ? `(${options.name})` : '';
describe(`RootProps${name}`, () => {