|
10 | 10 | import * as React from 'react';
|
11 | 11 | import { useState, useRef, useEffect, useMemo } from 'react';
|
12 | 12 | import KeyCode from 'rc-util/lib/KeyCode';
|
| 13 | +import isMobile from 'rc-util/lib/isMobile'; |
13 | 14 | import classNames from 'classnames';
|
14 | 15 | import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
15 | 16 | import type { ScrollTo } from 'rc-virtual-list/lib/List';
|
@@ -368,12 +369,19 @@ export default function generateSelector<
|
368 | 369 | const mergedShowSearch =
|
369 | 370 | showSearch !== undefined ? showSearch : isMultiple || mode === 'combobox';
|
370 | 371 |
|
| 372 | + // ======================== Mobile ======================== |
| 373 | + const [mobile, setMobile] = useState(false); |
| 374 | + useEffect(() => { |
| 375 | + // Only update on the client side |
| 376 | + setMobile(isMobile()); |
| 377 | + }, []); |
| 378 | + |
371 | 379 | // ============================== Ref ===============================
|
372 | 380 | const selectorDomRef = useRef<HTMLDivElement>(null);
|
373 | 381 |
|
374 | 382 | React.useImperativeHandle(ref, () => ({
|
375 |
| - focus: selectorRef.current.focus, |
376 |
| - blur: selectorRef.current.blur, |
| 383 | + focus: selectorRef.current?.focus, |
| 384 | + blur: selectorRef.current?.blur, |
377 | 385 | scrollTo: listRef.current?.scrollTo as ScrollTo,
|
378 | 386 | }));
|
379 | 387 |
|
@@ -885,8 +893,8 @@ export default function generateSelector<
|
885 | 893 |
|
886 | 894 | cancelSetMockFocused();
|
887 | 895 |
|
888 |
| - if (!popupElement.contains(document.activeElement)) { |
889 |
| - selectorRef.current.focus(); |
| 896 | + if (!mobile && !popupElement.contains(document.activeElement)) { |
| 897 | + selectorRef.current?.focus(); |
890 | 898 | }
|
891 | 899 | });
|
892 | 900 |
|
|
0 commit comments