fix(ui): adjust dropdown offset when flipped up
This commit is contained in:
@@ -67,34 +67,34 @@ export const GameDropdown: React.FC<GameDropdownProps> = ({
|
|||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
|
|
||||||
// Use passed position or fallback to last click position
|
// Use passed position or fallback to last click position
|
||||||
// Default offset of -10 to center mouse over menu
|
|
||||||
const targetX = position ? position.x : lastClickPos.x;
|
const targetX = position ? position.x : lastClickPos.x;
|
||||||
const targetY = position ? position.y : lastClickPos.y;
|
const targetY = position ? position.y : lastClickPos.y;
|
||||||
|
|
||||||
let x = targetX - 10;
|
let x = targetX - 10;
|
||||||
let y = targetY - 10;
|
|
||||||
|
// Determine flip direction first using raw position
|
||||||
let flipUp = false;
|
let flipUp = false;
|
||||||
|
|
||||||
// Simple adjustment logic (can be improved with measuring ref)
|
|
||||||
// We'll trust the parent passed reasonable coords, but ensure it doesn't go off-screen right/bottom
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
const viewportWidth = window.innerWidth;
|
|
||||||
const viewportHeight = window.innerHeight;
|
const viewportHeight = window.innerHeight;
|
||||||
|
|
||||||
// Approximate width if not measured yet (or use min-width)
|
|
||||||
const estimatedWidth = parseInt(width) || 200;
|
|
||||||
const estimatedHeight = 200; // Guess for now
|
const estimatedHeight = 200; // Guess for now
|
||||||
|
|
||||||
|
if (targetY + estimatedHeight > viewportHeight) {
|
||||||
|
flipUp = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust width constrained by viewport
|
||||||
|
const viewportWidth = window.innerWidth;
|
||||||
|
const estimatedWidth = parseInt(width) || 200;
|
||||||
if (x + estimatedWidth > viewportWidth) {
|
if (x + estimatedWidth > viewportWidth) {
|
||||||
x = viewportWidth - estimatedWidth - 10;
|
x = viewportWidth - estimatedWidth - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y + estimatedHeight > viewportHeight) {
|
|
||||||
// Flip up if space
|
|
||||||
flipUp = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply offset based on direction
|
||||||
|
// If flipping up, we want the bottom to be slightly below the mouse (y + 10)
|
||||||
|
// If flipping down, we want the top to be slightly above the mouse (y - 10)
|
||||||
|
const y = flipUp ? targetY + 10 : targetY - 10;
|
||||||
|
|
||||||
return createPortal(
|
return createPortal(
|
||||||
<div
|
<div
|
||||||
ref={dropdownRef}
|
ref={dropdownRef}
|
||||||
|
|||||||
Reference in New Issue
Block a user