Skip to content

Commit 68feaab

Browse files
authored
refactor: moved to utils (#5218)
1 parent 15ff5cf commit 68feaab

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

packages/components/src/components/input/input.lite.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getNumber,
3737
hasVoiceOver,
3838
isArrayOfStrings,
39+
isIOSSafari,
3940
stringPropVisible,
4041
uuid
4142
} from '../../utils';
@@ -159,22 +160,6 @@ export default function DBInput(props: DBInputProps) {
159160
}))
160161
: _list) || []
161162
);
162-
},
163-
// iOS Safari VoiceOver input:is([type="date"], [type="datetime-local"], [type="time"], [type="week"], [type="month"], [type="color"]) hack
164-
// TODO: We could remove this one again, after https://bugs.webkit.org/show_bug.cgi?id=294649 (mentioned in https://github.com/facebook/react/issues/33541) has been resolved.
165-
isIOSSafari: (): boolean => {
166-
if (
167-
typeof window === 'undefined' ||
168-
typeof navigator === 'undefined'
169-
)
170-
return false;
171-
const ua = navigator.userAgent;
172-
// iOS detection
173-
const isIOS = /iP(ad|hone|od)/.test(ua);
174-
// Safari detection (not Chrome or Firefox on iOS)
175-
const isSafari =
176-
!!ua.match(/Safari/) && !ua.match(/CriOS|FxiOS|OPiOS|EdgiOS/);
177-
return isIOS && isSafari;
178163
}
179164
});
180165

@@ -279,9 +264,14 @@ export default function DBInput(props: DBInputProps) {
279264
// iOS Safari VoiceOver input:is([type="date"], [type="datetime-local"], [type="time"], [type="week"], [type="month"], [type="color"]) hack
280265
// TODO: We could remove this one again, after https://bugs.webkit.org/show_bug.cgi?id=294649 (mentioned in https://github.com/facebook/react/issues/33541) has been resolved.
281266
role={
282-
['datetime-local', 'date', 'time', 'week', 'month', 'color'].includes(
283-
props.type ?? ''
284-
) && state.isIOSSafari()
267+
[
268+
'datetime-local',
269+
'date',
270+
'time',
271+
'week',
272+
'month',
273+
'color'
274+
].includes(props.type ?? '') && isIOSSafari()
285275
? 'textbox'
286276
: undefined
287277
}

packages/components/src/components/input/model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ export type DBInputProps = DBInputDefaultProps &
133133
export type DBInputDefaultState = {
134134
_dataListId?: string;
135135
getDataList: () => ValueLabelType[];
136-
isIOSSafari: () => boolean;
137136
};
138137

139138
export type DBInputState = DBInputDefaultState &

packages/components/src/utils/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ export const hasVoiceOver = (): boolean =>
5757
typeof window !== 'undefined' &&
5858
appleOs.some((os) => window.navigator.userAgent.includes(os));
5959

60+
/**
61+
* Determines if the current browser is Safari running on an iOS device.
62+
*
63+
* This function checks the user agent string to verify both iOS platform
64+
* (iPad, iPhone, or iPod) and Safari browser, excluding other browsers
65+
* such as Chrome, Firefox, Opera, and Edge on iOS.
66+
*
67+
* @returns {boolean} `true` if the browser is Safari on iOS, otherwise `false`.
68+
*/
69+
export const isIOSSafari = (): boolean => {
70+
if (typeof window === 'undefined' || typeof navigator === 'undefined')
71+
return false;
72+
const ua = navigator.userAgent;
73+
// iOS detection
74+
const isIOS = /iP(ad|hone|od)/.test(ua);
75+
// Safari detection (not Chrome or Firefox on iOS)
76+
const isSafari =
77+
!!ua.match(/Safari/) && !ua.match(/CriOS|FxiOS|OPiOS|EdgiOS/);
78+
return isIOS && isSafari;
79+
};
80+
6081
export const delay = (fn: () => void, ms: number) =>
6182
new Promise(() => setTimeout(fn, ms));
6283

0 commit comments

Comments
 (0)