feat(web): add auto-focus to composer input on desktop devices only

Adds touch device detection via media query (pointer: coarse) to prevent
triggering virtual keyboard on mobile. Input auto-focus is now conditional
on desktop environments where it improves keyboard-based interactions.
This commit is contained in:
weishu
2025-12-22 09:46:03 +08:00
parent dbcbc93ad0
commit aacab0be51
2 changed files with 11 additions and 1 deletions
+9
View File
@@ -16,6 +16,8 @@ export type PlatformHaptic = {
export type Platform = {
/** Whether running in Telegram Mini App */
isTelegram: boolean
/** Whether using a touch device (coarse pointer) */
isTouch: boolean
/** Haptic feedback (falls back to Vibration API on browser) */
haptic: PlatformHaptic
}
@@ -67,17 +69,24 @@ const haptic: PlatformHaptic = {
export function usePlatform(): Platform {
const isTelegram = useMemo(() => isTelegramApp(), [])
const isTouch = useMemo(
() => typeof window !== 'undefined' && window.matchMedia('(pointer: coarse)').matches,
[]
)
return {
isTelegram,
isTouch,
haptic
}
}
// Non-hook version for use outside React components
export function getPlatform(): Platform {
const isTouch = typeof window !== 'undefined' && window.matchMedia('(pointer: coarse)').matches
return {
isTelegram: isTelegramApp(),
isTouch,
haptic
}
}