fix: keep Settings open when dismissing dropdowns
This commit is contained in:
@@ -14,19 +14,35 @@ interface SettingsWindowProps {
|
|||||||
*/
|
*/
|
||||||
export const SettingsWindow: React.FC<SettingsWindowProps> = ({ open, onOpenChange }) => {
|
export const SettingsWindow: React.FC<SettingsWindowProps> = ({ open, onOpenChange }) => {
|
||||||
const descriptionId = React.useId();
|
const descriptionId = React.useId();
|
||||||
|
const skipNextOverlayClickRef = React.useRef(false);
|
||||||
|
|
||||||
|
const hasOpenFloatingMenu = React.useCallback(() => {
|
||||||
|
if (typeof document === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean(
|
||||||
|
document.querySelector('[data-slot="dropdown-menu-content"][data-state="open"], [data-slot="select-content"][data-state="open"]')
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogPrimitive.Root open={open} onOpenChange={onOpenChange}>
|
<DialogPrimitive.Root open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogPrimitive.Portal>
|
<DialogPrimitive.Portal>
|
||||||
<DialogPrimitive.Overlay
|
<DialogPrimitive.Overlay
|
||||||
className="fixed inset-0 z-50 bg-black/50 backdrop-blur-md"
|
className="fixed inset-0 z-50 bg-black/50 backdrop-blur-md"
|
||||||
onPointerDown={(event) => {
|
onPointerDown={() => {
|
||||||
event.stopPropagation();
|
skipNextOverlayClickRef.current = hasOpenFloatingMenu();
|
||||||
}}
|
|
||||||
onPointerUp={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
}}
|
}}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
if (skipNextOverlayClickRef.current) {
|
||||||
|
skipNextOverlayClickRef.current = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (hasOpenFloatingMenu()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
onOpenChange(false);
|
onOpenChange(false);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user