diff --git a/components/input-number/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/input-number/__tests__/__snapshots__/demo-extend.test.ts.snap index 1beb0a0572..a24a8beffe 100644 --- a/components/input-number/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/input-number/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -2835,6 +2835,152 @@ exports[`renders components/input-number/demo/filled-debug.tsx extend context co exports[`renders components/input-number/demo/filled-debug.tsx extend context correctly 2`] = `[]`; +exports[`renders components/input-number/demo/focus.tsx extend context correctly 1`] = ` +
Out of range
Prefix / Suffix
Status
+Focus
Icon
_InternalPanelDoNotUseOrYouWillBeFired
Override Component Style
@@ -70,11 +71,11 @@ Common props ref:[Common props](/docs/react/common-props)
## Ref
-| Name | Description | Version |
-| ------------- | ---------------------- | ------- |
-| blur() | Remove focus | |
-| focus() | Get focus | |
-| nativeElement | The native DOM element | 5.17.3 |
+| Name | Description | Type | Version |
+| --- | --- | --- | --- |
+| blur() | Remove focus | - | |
+| focus() | Get focus | (option?: { preventScroll?: boolean, cursor?: 'start' \| 'end' \| 'all' }) | cursor - 5.23.0 |
+| nativeElement | The native DOM element | - | 5.17.3 |
## Design Token
diff --git a/components/input-number/index.tsx b/components/input-number/index.tsx
index c7dd02bf81..f8d426d1cf 100644
--- a/components/input-number/index.tsx
+++ b/components/input-number/index.tsx
@@ -10,12 +10,12 @@ import type { InputStatus } from '../_util/statusUtils';
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
import { devUseWarning } from '../_util/warning';
import ConfigProvider, { ConfigContext } from '../config-provider';
+import type { Variant } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
import useSize from '../config-provider/hooks/useSize';
import type { SizeType } from '../config-provider/SizeContext';
import { FormItemInputContext } from '../form/context';
-import type { Variant } from '../config-provider';
import useVariant from '../form/hooks/useVariants';
import { useCompactItemContext } from '../space/Compact';
import useStyle from './style';
diff --git a/components/input-number/index.zh-CN.md b/components/input-number/index.zh-CN.md
index dd60a61722..989168ea6a 100644
--- a/components/input-number/index.zh-CN.md
+++ b/components/input-number/index.zh-CN.md
@@ -30,6 +30,7 @@ demo:
超出边界
前缀/后缀
自定义状态
+聚焦
图标按钮
_InternalPanelDoNotUseOrYouWillBeFired
覆盖组件样式
@@ -71,11 +72,11 @@ demo:
## Ref
-| 名称 | 描述 | 版本 |
-| ------------- | ----------------- | ------ |
-| blur() | 移除焦点 | |
-| focus() | 获取焦点 | |
-| nativeElement | 获取原生 DOM 元素 | 5.17.3 |
+| 名称 | 说明 | 参数 | 版本 |
+| --- | --- | --- | --- |
+| blur() | 移除焦点 | - | |
+| focus() | 获取焦点 | (option?: { preventScroll?: boolean, cursor?: 'start' \| 'end' \| 'all' }) | cursor - 5.23.0 |
+| nativeElement | 获取原生 DOM 元素 | - | 5.17.3 |
## 主题变量(Design Token)
diff --git a/components/input/Input.tsx b/components/input/Input.tsx
index 9c20dbb8b1..7c19c33a6a 100644
--- a/components/input/Input.tsx
+++ b/components/input/Input.tsx
@@ -2,6 +2,7 @@ import React, { forwardRef, useContext, useEffect, useRef } from 'react';
import classNames from 'classnames';
import type { InputRef, InputProps as RcInputProps } from 'rc-input';
import RcInput from 'rc-input';
+import { InputFocusOptions, triggerFocus } from 'rc-input/lib/utils/commonUtils';
import { composeRef } from 'rc-util/lib/ref';
import ContextIsolator from '../_util/ContextIsolator';
@@ -10,51 +11,21 @@ import type { InputStatus } from '../_util/statusUtils';
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
import { devUseWarning } from '../_util/warning';
import { ConfigContext } from '../config-provider';
+import type { Variant } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
import useSize from '../config-provider/hooks/useSize';
import type { SizeType } from '../config-provider/SizeContext';
import { FormItemInputContext } from '../form/context';
-import type { Variant } from '../config-provider';
import useVariant from '../form/hooks/useVariants';
import { useCompactItemContext } from '../space/Compact';
import useRemovePasswordTimeout from './hooks/useRemovePasswordTimeout';
import useStyle from './style';
import { hasPrefixSuffix } from './utils';
-export interface InputFocusOptions extends FocusOptions {
- cursor?: 'start' | 'end' | 'all';
-}
-
+export type { InputFocusOptions };
export type { InputRef };
-
-export function triggerFocus(
- element?: HTMLInputElement | HTMLTextAreaElement,
- option?: InputFocusOptions,
-) {
- if (!element) {
- return;
- }
-
- element.focus(option);
-
- // Selection content
- const { cursor } = option || {};
- if (cursor) {
- const len = element.value.length;
-
- switch (cursor) {
- case 'start':
- element.setSelectionRange(0, 0);
- break;
- case 'end':
- element.setSelectionRange(len, len);
- break;
- default:
- element.setSelectionRange(0, len);
- }
- }
-}
+export { triggerFocus };
export interface InputProps
extends Omit<
diff --git a/package.json b/package.json
index 11429f9f68..658a3f2a7b 100644
--- a/package.json
+++ b/package.json
@@ -129,7 +129,7 @@
"rc-field-form": "~2.5.0",
"rc-image": "~7.11.0",
"rc-input": "~1.6.3",
- "rc-input-number": "~9.2.0",
+ "rc-input-number": "~9.3.0",
"rc-mentions": "~2.16.1",
"rc-menu": "~9.15.1",
"rc-motion": "^2.9.3",