fix(ui): ensure dropdown position stays sticky on interaction
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import './GameDropdown.css';
|
import './GameDropdown.css';
|
||||||
|
|
||||||
@@ -38,6 +38,10 @@ export const GameDropdown: React.FC<GameDropdownProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
// Capture position ONCE on mount (or first render) if not provided
|
||||||
|
// This prevents the menu from jumping if the user clicks inside it (changing lastClickPos)
|
||||||
|
const [capturedPos] = useState(() => position || lastClickPos);
|
||||||
|
|
||||||
// Handle click outside
|
// Handle click outside
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isOpen) return;
|
if (!isOpen) return;
|
||||||
@@ -52,7 +56,6 @@ export const GameDropdown: React.FC<GameDropdownProps> = ({
|
|||||||
document.addEventListener('mousedown', handleClickOutside);
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
|
||||||
// Handle scroll to update position or close?
|
// Handle scroll to update position or close?
|
||||||
// For now, simpler to just close on scroll or let it float (fixed pos)
|
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
// Optional: onClose();
|
// Optional: onClose();
|
||||||
};
|
};
|
||||||
@@ -66,9 +69,10 @@ 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 (if updated dynamically) or fall back to the captured sticky position
|
||||||
const targetX = position ? position.x : lastClickPos.x;
|
const target = position || capturedPos;
|
||||||
const targetY = position ? position.y : lastClickPos.y;
|
const targetX = target.x;
|
||||||
|
const targetY = target.y;
|
||||||
|
|
||||||
let x = targetX - 10;
|
let x = targetX - 10;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user