Skip to content

An open-source, self-hosted system for apps built with web technologies.

Menus and dialogs stack where they belong

zohayrslileh554e8142fb14
diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsx
index 8877b8f..81c784d 100644
--- a/source/client/view/appearance/appearance.tsx
+++ b/source/client/view/appearance/appearance.tsx
@@ -21,7 +21,6 @@ export default function ({ children }: PropsWithChildren) {
function AppearanceRoot({ children }: PropsWithChildren) {
const { resolved } = useDesktopPreferences()
const [appearance, setAppearance] = useState(() => resolveStoredAppearance(localStorage.getItem(appearanceKey)))
- const [overlays, setOverlays] = useState<HTMLDivElement | null>(null)
const remember = useCallback(function (value: Appearance) {
setAppearance(value)
localStorage.setItem(appearanceKey, JSON.stringify(value))
@@ -38,7 +37,8 @@ function AppearanceRoot({ children }: PropsWithChildren) {
<UIProvider appearance={appearance} preferences={resolved}>
- <DesktopScaleProvider scale={resolved.scale} container={overlays}>
+ {/* What opens over the Desktop has its container in the Desktop's own layer (Structure). */}
+ <DesktopScaleProvider scale={resolved.scale} container={null}>
<div className="relative isolate h-dvh overflow-hidden" style={{ backgroundColor: background }}>
@@ -51,11 +51,6 @@ function AppearanceRoot({ children }: PropsWithChildren) {
{children}
- {/* Desktop overlays open here: inside the scale, so they share it, and outside the
- layout, so opening one never takes room from the Desktop. It has no size and
- catches nothing; what opens in it floats from its corner. */}
- <div ref={setOverlays} className="absolute top-0 left-0 size-0 overflow-visible" />
-
</div>
</ReducedMotion>
diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx
index c27df61..29b4149 100644
--- a/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx
+++ b/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx
@@ -6,7 +6,7 @@ import { Badge, ContextMenu, GridList, Table, Text, useAppearance, useScale, Scr
import { useRef, useState, type ReactElement } from "react"
import Empty from "../empty"
import ProgramMenu from "../../program-menu"
-import { useDesktopScaleContainer } from "@client/view/structure/desktop/desktop-scale"
+import { useStartMenuSurface } from "../start-menu"
export type ProgramsLayout = "grid" | "list"
@@ -24,7 +24,7 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:
const space = useScale(useAppearance().spacing)
- const scaleContainer = useDesktopScaleContainer()
+ const surface = useStartMenuSurface()
// The Program a press for the menu landed on, found under the pointer as the menu opens.
const [menuFor, setMenuFor] = useState<Program | null>(null)
@@ -45,7 +45,7 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:
setMenuFor(key ? byIdentity.get(key) ?? null : null)
}}>{list}</div>
</ContextMenu.Trigger>
- <ContextMenu.Content portalContainer={scaleContainer ?? undefined}>
+ <ContextMenu.Content portalContainer={surface ?? undefined}>
{menuFor && <ProgramMenu program={menuFor} onOpen={() => onLaunch(menuFor)} />}
</ContextMenu.Content>
</ContextMenu>
diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx
index 3930219..ff0279a 100644
--- a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx
+++ b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx
@@ -142,6 +142,19 @@ function useStartMenuControl() {
return value
}
+/**
+ * The Start Menu's own surface: what floats from inside it, such as a menu, opens there, since the
+ * Start Menu stands above everything else on the page and a press outside it closes it.
+ */
+export function useStartMenuSurface() {
+ return useStartMenuControl().popover.surface.current
+}
+
+/** Closes the Start Menu, as choosing something in it does. */
+export function useCloseStartMenu() {
+ return useStartMenuControl().popover.close
+}
+
/** Whether the default Shell's Start Menu currently retains its Taskbar anchor. */
export function useStartMenuOpen() {
return useStartMenuControl().popover.open
diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsx
index 1db612b..c251fe7 100644
--- a/source/client/view/structure/structure.tsx
+++ b/source/client/view/structure/structure.tsx
@@ -4,6 +4,7 @@ import { LinkManagerSnapshot } from "@server/core/link-manager/link-manager"
import LinkManager from "@client/core/link-manager/link-manager"
import { timing, useAppearance } from "@phreshos/react-ui"
import Loading from "../components/loading"
+import { DesktopScaleProvider, useDesktopScale } from "./desktop/desktop-scale"
import Alert from "../components/alert"
import { ApplicationContext, LinkManagerContext } from "../contexts"
import usePromise from "@libs/react-promise"
@@ -24,10 +25,27 @@ import {
export default function () {
const appearance = useAppearance()
+ const scale = useDesktopScale()
+ const [overlays, setOverlays] = useState<HTMLDivElement | null>(null)
return <Readiness requirements={startupRequirements}>
- <Desktop />
+ {/* The Desktop and what opens over it, such as a dialog, are one layer: whatever stacks inside it
+ stays inside, and the readiness cover stands above all of it. */}
+ <div className="relative isolate grid">
+
+ <DesktopScaleProvider scale={scale} container={overlays}>
+
+ <Desktop />
+
+ </DesktopScaleProvider>
+
+ {/* Desktop overlays open here: inside the scale, so they share it, and outside the layout, so
+ opening one never takes room from the Desktop. It has no size and catches nothing; what
+ opens in it floats from its corner. */}
+ <div ref={setOverlays} className="absolute top-0 left-0 size-0 overflow-visible" />
+
+ </div>
<DesktopReadiness appearance={appearance} />