fix(web): keep chat context menu within viewport
All checks were successful
CI / test (push) Successful in 21s
All checks were successful
CI / test (push) Successful in 21s
- adjust right-click menu coordinates to avoid clipping near screen edges
This commit is contained in:
@@ -84,8 +84,9 @@ export function ChatList() {
|
||||
onClick={() => setActiveChatId(chat.id)}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
const safePos = getSafeContextPosition(e.clientX, e.clientY);
|
||||
setCtxChatId(chat.id);
|
||||
setCtxPos({ x: e.clientX, y: e.clientY });
|
||||
setCtxPos(safePos);
|
||||
}}
|
||||
>
|
||||
<div className="flex items-start gap-3">
|
||||
@@ -155,3 +156,11 @@ export function ChatList() {
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
function getSafeContextPosition(x: number, y: number): { x: number; y: number } {
|
||||
const menuWidth = 176;
|
||||
const menuHeight = 56;
|
||||
const pad = 8;
|
||||
const safeX = Math.min(Math.max(pad, x), window.innerWidth - menuWidth - pad);
|
||||
const safeY = Math.min(Math.max(pad, y), window.innerHeight - menuHeight - pad);
|
||||
return { x: safeX, y: safeY };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user