mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +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}`,
|
`Focusing textarea on location state change: ${location.pathname}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Check if the device is not a touchscreen */
|
const hasCoarsePointer = window.matchMedia?.('(pointer: coarse)').matches;
|
||||||
if (!window.matchMedia?.('(pointer: coarse)').matches) {
|
const hasHover = window.matchMedia?.('(hover: hover)').matches;
|
||||||
textAreaRef.current?.focus();
|
|
||||||
|
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,
|
replace: true,
|
||||||
state: {},
|
state: {},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue