mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
📱 fix: Improve Mobile Chat Focus Detection and Navigation (#10125)
This commit is contained in:
parent
3d1cedb85b
commit
c602088178
1 changed files with 14 additions and 4 deletions
|
|
@ -12,12 +12,22 @@ export default function useFocusChatEffect(textAreaRef: React.RefObject<HTMLText
|
|||
`Focusing textarea on location state change: ${location.pathname}`,
|
||||
);
|
||||
|
||||
/** Check if the device is not a touchscreen */
|
||||
if (!window.matchMedia?.('(pointer: coarse)').matches) {
|
||||
textAreaRef.current?.focus();
|
||||
const hasCoarsePointer = window.matchMedia?.('(pointer: coarse)').matches;
|
||||
const hasHover = window.matchMedia?.('(hover: hover)').matches;
|
||||
|
||||
const path = `${location.pathname}${window.location.search ?? ''}`;
|
||||
/* Early return if mobile-like: has coarse pointer OR lacks hover */
|
||||
if (hasCoarsePointer || !hasHover) {
|
||||
navigate(path, {
|
||||
replace: true,
|
||||
state: {},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
navigate(`${location.pathname}${window.location.search ?? ''}`, {
|
||||
textAreaRef.current?.focus();
|
||||
|
||||
navigate(path, {
|
||||
replace: true,
|
||||
state: {},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue