Skip to content

Commit

Permalink
fix: unable to open phone input country picker on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
HellWolf93 committed Dec 18, 2023
1 parent a372cdc commit 27c1ebf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/PhoneInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { useCountry, useCountries } from './hooks';
import CountriesDropdown from './countriesDropdown';
import positionResolver from './helpers/positionResolver';
import useIsMobile from '../../libs/hooks/useIsMobile';

/**
* phone input are used for freeform data entry.
Expand Down Expand Up @@ -89,6 +90,7 @@ const PhoneInput = React.forwardRef((props, ref) => {
const [isOpen, setIsOpen] = useState(false);
const [hasFocus, setHasFocus] = useState(false);

const isMobile = useIsMobile();
useOutsideClick(
pickerRef,
event => {
Expand All @@ -108,7 +110,7 @@ const PhoneInput = React.forwardRef((props, ref) => {
triggerElementRef: () => triggerRef,
threshold: 10,
});
useWindowResize(() => setIsOpen(false), isOpen);
useWindowResize(() => setIsOpen(false), isOpen && !isMobile);

useEffect(() => {
if (isOpen) searchRef.current.focus();
Expand Down
2 changes: 2 additions & 0 deletions src/libs/hooks/useIsMobile.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function useIsMobile(): boolean;
export default useIsMobile;
8 changes: 8 additions & 0 deletions src/libs/hooks/useIsMobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useMemo } from 'react';
import isMobileFn from '../utils/isMobile';

export default function useIsMobile() {
const isMobile = useMemo(() => isMobileFn(), []);

return isMobile;
}
2 changes: 2 additions & 0 deletions src/libs/utils/isMobile.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function isMobile(): boolean;
export default isMobile;
17 changes: 17 additions & 0 deletions src/libs/utils/isMobile.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 27c1ebf

Please sign in to comment.