Skip to content

Commit 0ed970b

Browse files
committed
fix(website): fix mobile Dropdown
1 parent 469a636 commit 0ed970b

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

apps/website/src/components/LocaleSwitcher/LocaleSwitcher.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import { Link } from '@components/Link/Link';
44
import { getHTMLTextDir, getLocaleName } from '@intlayer/core';
55
import {
6+
Container,
67
DropDown,
78
Input,
89
type PanelProps,
9-
Container,
1010
} from '@intlayer/design-system';
1111
import { MoveVertical } from 'lucide-react';
1212
import { useIntlayer, useLocale } from 'next-intlayer';

packages/@intlayer/design-system/src/components/DropDown/index.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FC, HTMLAttributes } from 'react';
2+
import { checkIsIphoneOrSafariDevice } from '../../hooks';
23
import { cn } from '../../utils/cn';
34
import { MaxHeightSmoother } from '../MaxHeightSmoother';
45

@@ -71,6 +72,13 @@ const Trigger: FC<TriggerProps> = ({
7172
<button
7273
className={cn('w-full cursor-pointer', className)}
7374
aria-label={`Open panel ${identifier}`}
75+
onClick={(e) => {
76+
const isIOS = checkIsIphoneOrSafariDevice();
77+
if (isIOS) {
78+
(e.currentTarget as HTMLButtonElement).focus({ preventScroll: true });
79+
}
80+
}}
81+
onBlur={(e) => (e.currentTarget as HTMLButtonElement).blur()}
7482
{...props}
7583
>
7684
{children}

packages/@intlayer/design-system/src/hooks/useDevice.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
44

55
export type SizeType = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
66

7-
const getBreakpointFromSize = (breakpoint: SizeType | number) => {
7+
export const getBreakpointFromSize = (breakpoint: SizeType | number) => {
88
switch (breakpoint) {
99
case 'sm':
1010
return 640;
@@ -21,7 +21,7 @@ const getBreakpointFromSize = (breakpoint: SizeType | number) => {
2121
}
2222
};
2323

24-
const checkIsMobileUserAgent = (): boolean | undefined => {
24+
export const checkIsMobileUserAgent = (): boolean | undefined => {
2525
if (typeof window === 'undefined') return;
2626

2727
const userAgent = window.navigator?.userAgent;
@@ -33,7 +33,25 @@ const checkIsMobileUserAgent = (): boolean | undefined => {
3333
);
3434
};
3535

36-
const checkIsMobileScreen = (breakpoint: number): boolean | undefined => {
36+
export const checkIsIphoneOrSafariDevice = (): boolean | undefined => {
37+
if (typeof window === 'undefined') return;
38+
39+
const userAgent = window.navigator?.userAgent;
40+
41+
/* 1 . is it Safari? (Chrome & co. also contain “Safari/…”, so exclude them) */
42+
const isSafari =
43+
/Safari\/\d/i.test(userAgent) && // has “Safari/xxx”
44+
!/Chrome|CriOS|FxiOS|Edg|OPR/i.test(userAgent); // …but not the other browsers
45+
46+
/* 2. is it an Apple device? (macOS or iOS/iPadOS) */
47+
const isAppleDevice = /Macintosh|iP(?:hone|ad|od)/.test(userAgent);
48+
49+
return isSafari && isAppleDevice; // true for mac-Safari & iOS-Safari
50+
};
51+
52+
export const checkIsMobileScreen = (
53+
breakpoint: number
54+
): boolean | undefined => {
3755
if (typeof window === 'undefined') return;
3856

3957
return (window?.innerWidth ?? 0) <= breakpoint;
@@ -45,7 +63,7 @@ type UseDeviceState = {
4563
isMobile: boolean | undefined;
4664
};
4765

48-
const calculateIsMobile = (breakpoint: SizeType | number) => {
66+
export const calculateIsMobile = (breakpoint: SizeType | number = 'md') => {
4967
const breakpointValue = getBreakpointFromSize(breakpoint);
5068

5169
const isMobileUserAgent = checkIsMobileUserAgent();

0 commit comments

Comments
 (0)