(null);
+ useLayoutEffect(() => {
+ if (ref.current) {
+ ref.current.focus({ preventScroll: true });
+ }
+ }, []);
+ return (
+
+
+
+ );
+};
+
+const Demo = () => {
+ const [open, setOpen] = useState(false);
+ return (
+
+ );
+};
+
+export default Demo;
diff --git a/src/BaseSelect.tsx b/src/BaseSelect.tsx
index 3208301d..912142a1 100644
--- a/src/BaseSelect.tsx
+++ b/src/BaseSelect.tsx
@@ -70,7 +70,7 @@ export type CustomTagProps = {
};
export interface BaseSelectRef {
- focus: () => void;
+ focus: (options?: FocusOptions) => void;
blur: () => void;
scrollTo: ScrollTo;
}
diff --git a/src/Selector/index.tsx b/src/Selector/index.tsx
index 711bf276..e0ca1726 100644
--- a/src/Selector/index.tsx
+++ b/src/Selector/index.tsx
@@ -8,15 +8,15 @@
* - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
*/
-import * as React from 'react';
-import { useRef } from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import type { ScrollTo } from 'rc-virtual-list/lib/List';
-import MultipleSelector from './MultipleSelector';
-import SingleSelector from './SingleSelector';
-import useLock from '../hooks/useLock';
+import * as React from 'react';
+import { useRef } from 'react';
import type { CustomTagProps, DisplayValueType, Mode, RenderNode } from '../BaseSelect';
+import useLock from '../hooks/useLock';
import { isValidateOpenKey } from '../utils/keyUtil';
+import MultipleSelector from './MultipleSelector';
+import SingleSelector from './SingleSelector';
export interface InnerSelectorProps {
prefixCls: string;
@@ -47,7 +47,7 @@ export interface InnerSelectorProps {
}
export interface RefSelectorProps {
- focus: () => void;
+ focus: (options?: FocusOptions) => void;
blur: () => void;
scrollTo?: ScrollTo;
}
@@ -122,8 +122,8 @@ const Selector: React.ForwardRefRenderFunction
// ======================= Ref =======================
React.useImperativeHandle(ref, () => ({
- focus: () => {
- inputRef.current.focus();
+ focus: (options) => {
+ inputRef.current.focus(options);
},
blur: () => {
inputRef.current.blur();