Skip to content

Commit fd852fe

Browse files
authored
added mobile check on the focus after blur event (#611)
1 parent d5018f5 commit fd852fe

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/generate.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import * as React from 'react';
1111
import { useState, useRef, useEffect, useMemo } from 'react';
1212
import KeyCode from 'rc-util/lib/KeyCode';
13+
import isMobile from 'rc-util/lib/isMobile';
1314
import classNames from 'classnames';
1415
import useMergedState from 'rc-util/lib/hooks/useMergedState';
1516
import type { ScrollTo } from 'rc-virtual-list/lib/List';
@@ -368,12 +369,19 @@ export default function generateSelector<
368369
const mergedShowSearch =
369370
showSearch !== undefined ? showSearch : isMultiple || mode === 'combobox';
370371

372+
// ======================== Mobile ========================
373+
const [mobile, setMobile] = useState(false);
374+
useEffect(() => {
375+
// Only update on the client side
376+
setMobile(isMobile());
377+
}, []);
378+
371379
// ============================== Ref ===============================
372380
const selectorDomRef = useRef<HTMLDivElement>(null);
373381

374382
React.useImperativeHandle(ref, () => ({
375-
focus: selectorRef.current.focus,
376-
blur: selectorRef.current.blur,
383+
focus: selectorRef.current?.focus,
384+
blur: selectorRef.current?.blur,
377385
scrollTo: listRef.current?.scrollTo as ScrollTo,
378386
}));
379387

@@ -885,8 +893,8 @@ export default function generateSelector<
885893

886894
cancelSetMockFocused();
887895

888-
if (!popupElement.contains(document.activeElement)) {
889-
selectorRef.current.focus();
896+
if (!mobile && !popupElement.contains(document.activeElement)) {
897+
selectorRef.current?.focus();
890898
}
891899
});
892900

0 commit comments

Comments
 (0)