fix: centralize iOS safe area and refactor list components (#47)

* fix: add iOS safe-area-inset-top support for fullscreen overlays

- Add pt-safe CSS utility class for safe-area-inset-top
- Create FullscreenSheet component with built-in safe-area support
- Add fullscreen prop to DialogContent for fullscreen dialogs
- Update FileBrowserSheet to use FullscreenSheet
- Update MobileFilePreviewModal to use FullscreenSheet
- Add pt-safe to SettingsDialog mobile view

Fixes status bar overlap on iOS devices with notch/Dynamic Island

* fix: add pt-safe to main page headers

- Header.tsx (main repos page)
- SessionDetailHeader.tsx (session page)

* docs: add TDD refactoring plan for iOS safe area

* remove plan file from repo

* refactor: centralize iOS safe area handling with PageHeader component

- Add PageHeader component with pt-safe, sticky, z-10, border-b styling
- Add TDD test infrastructure (vitest config, testing-library, jsdom)
- Refactor Header, SessionDetailHeader, RepoDetailHeader, Workspace to use PageHeader
- Fix missing pt-safe on RepoDetailHeader and Workspace pages
- All header safe area styling now has single fix point

* fix: add pt-safe to remaining fullscreen dialogs and sheets

- GitChangesSheet, FilePreviewDialog: add fullscreen prop
- ModelSelectDialog, RepoMcpDialog: add pt-safe class
- EditSessionTitleDialog: add pt-safe on mobile

* fix: use mobile-first positioning for large dialogs

Dialogs need top-0 positioning on mobile for pt-safe to work.
Centered dialogs don't benefit from safe area padding.

* fix: add mobileFullscreen prop to DialogContent

- Fullscreen on mobile with pt-safe, centered on desktop
- Simplifies large dialog styling

* fix: use inline styles for iOS safe area to fix CSS cascade issues

- Convert pt-safe/pb-safe to @utility directives with iOS 11 fallback
- Use inline styles on DialogContent for reliable safe-area padding
- Position close button with calc(env(safe-area-inset-top) + 1rem)
- Add 10 tests for DialogContent safe-area behavior

* refactor: extract ListToolbar and Header components for reuse

- Add ListToolbar component for search/select all/delete UI
- Add Header compound component (Header.Root, Header.Title, etc.)
- Update SessionList and RepoList to use ListToolbar
- Mobile delete: deletes selected or all if none selected
- Cancel delete now clears selection
- Remove unused layout components

---------

Co-authored-by: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
This commit is contained in:
Justin CarlsonandChris Scott authored and GitHub committed 2026-01-04 14:05:59 -05:00
1 parent 72bb20a4fa
commit cd9a552bf8
34 files changed
+1627 -986

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ interface DeleteDialogProps {
onConfirm: () => void
onCancel: () => void
title: string
description: string
description: React.ReactNode
itemName?: string
isDeleting?: boolean
}
+134
View File
@@ -0,0 +1,134 @@
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "./dialog";
describe("DialogContent", () => {
it("applies safe-area padding when fullscreen prop is true", () => {
render(
<Dialog open>
<DialogContent fullscreen data-testid="dialog-content">
<DialogHeader>
<DialogTitle>Test Dialog</DialogTitle>
</DialogHeader>
</DialogContent>
</Dialog>
);
const content = screen.getByTestId("dialog-content");
expect(content).toHaveStyle({ paddingTop: "env(safe-area-inset-top, 0px)" });
});
it("applies safe-area padding when mobileFullscreen prop is true", () => {
render(
<Dialog open>
<DialogContent mobileFullscreen data-testid="dialog-content">
<DialogHeader>
<DialogTitle>Test Dialog</DialogTitle>
</DialogHeader>
</DialogContent>
</Dialog>
);
const content = screen.getByTestId("dialog-content");
expect(content).toHaveStyle({ paddingTop: "env(safe-area-inset-top, 0px)" });
});
it("applies inset-0 for fullscreen dialogs", () => {
render(
<Dialog open>
<DialogContent fullscreen data-testid="dialog-content">
Content
</DialogContent>
</Dialog>
);
const content = screen.getByTestId("dialog-content");
expect(content).toHaveClass("inset-0");
});
it("applies inset-0 for mobileFullscreen dialogs", () => {
render(
<Dialog open>
<DialogContent mobileFullscreen data-testid="dialog-content">
Content
</DialogContent>
</Dialog>
);
const content = screen.getByTestId("dialog-content");
expect(content).toHaveClass("inset-0");
});
it("does not apply safe-area padding when neither fullscreen nor mobileFullscreen", () => {
render(
<Dialog open>
<DialogContent data-testid="dialog-content">
Content
</DialogContent>
</Dialog>
);
const content = screen.getByTestId("dialog-content");
const style = content.getAttribute("style") || "";
expect(style).not.toContain("safe-area");
expect(content).not.toHaveClass("inset-0");
});
it("hides close button when fullscreen is true", () => {
render(
<Dialog open>
<DialogContent fullscreen data-testid="dialog-content">
Content
</DialogContent>
</Dialog>
);
expect(screen.queryByRole("button", { name: /close/i })).not.toBeInTheDocument();
});
it("shows close button when mobileFullscreen is true", () => {
render(
<Dialog open>
<DialogContent mobileFullscreen data-testid="dialog-content">
Content
</DialogContent>
</Dialog>
);
expect(screen.getByRole("button", { name: /close/i })).toBeInTheDocument();
});
it("hides close button when hideCloseButton is true", () => {
render(
<Dialog open>
<DialogContent hideCloseButton data-testid="dialog-content">
Content
</DialogContent>
</Dialog>
);
expect(screen.queryByRole("button", { name: /close/i })).not.toBeInTheDocument();
});
it("merges custom className with default classes", () => {
render(
<Dialog open>
<DialogContent className="custom-class" data-testid="dialog-content">
Content
</DialogContent>
</Dialog>
);
const content = screen.getByTestId("dialog-content");
expect(content).toHaveClass("custom-class");
expect(content).toHaveClass("fixed");
expect(content).toHaveClass("z-50");
});
it("renders children correctly", () => {
render(
<Dialog open>
<DialogContent>
<span>Test Child Content</span>
</DialogContent>
</Dialog>
);
expect(screen.getByText("Test Child Content")).toBeInTheDocument();
});
});
+41 -22
View File
@@ -30,33 +30,52 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
interface DialogContentProps
extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
hideCloseButton?: boolean
fullscreen?: boolean
mobileFullscreen?: boolean
}
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
DialogContentProps
>(({ className, children, hideCloseButton, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
aria-describedby={undefined}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-[90%] max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg [&.w-screen]:left-0 [&.w-screen]:top-0 [&.w-screen]:translate-x-0 [&.w-screen]:translate-y-0",
className
)}
{...props}
>
{children}
{!hideCloseButton && (
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
))
>(({ className, children, hideCloseButton, fullscreen, mobileFullscreen, ...props }, ref) => {
const isMobileFullscreenMode = fullscreen || mobileFullscreen
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
aria-describedby={undefined}
className={cn(
"fixed z-50 grid gap-4 border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
fullscreen
? "inset-0 w-full h-full max-w-none max-h-none p-0 rounded-none"
: mobileFullscreen
? "inset-0 w-full h-full max-w-none max-h-none p-0 rounded-none sm:inset-auto sm:left-[50%] sm:top-[50%] sm:w-[90%] sm:max-w-lg sm:max-h-none sm:translate-x-[-50%] sm:translate-y-[-50%] sm:p-6 sm:rounded-lg"
: "left-[50%] top-[50%] w-[90%] max-w-lg translate-x-[-50%] translate-y-[-50%] p-6 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
style={isMobileFullscreenMode ? {
paddingTop: 'env(safe-area-inset-top, 0px)',
} : undefined}
{...props}
>
{children}
{!hideCloseButton && !fullscreen && (
<DialogPrimitive.Close
className="absolute right-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"
style={mobileFullscreen ? {
top: 'calc(env(safe-area-inset-top, 0px) + 1rem)',
} : { top: '1rem' }}
>
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
)
})
DialogContent.displayName = DialogPrimitive.Content.displayName
const DialogHeader = ({
@@ -0,0 +1,63 @@
import * as React from "react"
import { cn } from "@/lib/utils"
interface FullscreenSheetProps {
children: React.ReactNode
className?: string
style?: React.CSSProperties
}
interface FullscreenSheetHeaderProps {
children: React.ReactNode
className?: string
}
interface FullscreenSheetContentProps {
children: React.ReactNode
className?: string
}
const FullscreenSheet = React.forwardRef<HTMLDivElement, FullscreenSheetProps>(
({ children, className, style, ...props }, ref) => (
<div
ref={ref}
className={cn("fixed inset-0 z-50 bg-background flex flex-col", className)}
style={style}
{...props}
>
{children}
</div>
)
)
FullscreenSheet.displayName = "FullscreenSheet"
const FullscreenSheetHeader = React.forwardRef<HTMLDivElement, FullscreenSheetHeaderProps>(
({ children, className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"flex-shrink-0 border-b border-border bg-background backdrop-blur-sm pt-safe",
className
)}
{...props}
>
{children}
</div>
)
)
FullscreenSheetHeader.displayName = "FullscreenSheetHeader"
const FullscreenSheetContent = React.forwardRef<HTMLDivElement, FullscreenSheetContentProps>(
({ children, className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex-1 overflow-hidden min-h-0", className)}
{...props}
>
{children}
</div>
)
)
FullscreenSheetContent.displayName = "FullscreenSheetContent"
export { FullscreenSheet, FullscreenSheetHeader, FullscreenSheetContent }
+227
View File
@@ -0,0 +1,227 @@
import { Settings } from "lucide-react";
import { Button } from "@/components/ui/button";
import { BackButton } from "@/components/ui/back-button";
import { PageHeader } from "@/components/ui/page-header";
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
import { useTheme } from "@/hooks/useTheme";
import { EditSessionTitleDialog } from "@/components/session/EditSessionTitleDialog";
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { MoreVertical } from "lucide-react";
import { cn } from "@/lib/utils";
import type { ReactNode } from "react";
import { useState, useEffect } from "react";
import { useMobile } from "@/hooks/useMobile";
import { Loader2, X } from "lucide-react";
interface HeaderProps {
children: ReactNode;
className?: string;
}
function HeaderBase({ children, className, ...props }: HeaderProps) {
return (
<PageHeader className={cn("flex-shrink-0", className)} {...props}>
<div className="flex items-center justify-between px-2 sm:px-4 py-1.5 sm:py-2">
{children}
</div>
</PageHeader>
);
}
function HeaderBackButton({ to, className }: { to?: string; className?: string }) {
return to ? <BackButton to={to} className={className} /> : null;
}
interface HeaderTitleProps {
children: ReactNode;
logo?: boolean;
className?: string;
}
function HeaderTitle({ children, logo, className }: HeaderTitleProps) {
const theme = useTheme();
return (
<div className={cn("flex items-center gap-2", className)}>
{logo && typeof children === "string" && children === "OpenCode" ? (
<img
src={theme === 'light' ? "/opencode-wordmark-light.svg" : "/opencode-wordmark-dark.svg"}
alt="OpenCode"
className="h-6 w-auto sm:h-8"
/>
) : (
<h1 className="text-xl font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate">
{children}
</h1>
)}
</div>
);
}
interface HeaderEditableTitleProps {
value: string;
onChange: (value: string) => void;
subtitle?: string;
generating?: boolean;
className?: string;
}
function HeaderEditableTitle({ value, onChange, subtitle, generating, className }: HeaderEditableTitleProps) {
const [isEditing, setIsEditing] = useState(false);
const [editTitle, setEditTitle] = useState(value);
const isMobile = useMobile();
useEffect(() => {
if (!isEditing) {
setEditTitle(value);
}
}, [value, isEditing]);
const handleTitleClick = () => {
setIsEditing(true);
setEditTitle(value);
};
const handleTitleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (editTitle.trim() && editTitle !== value) {
onChange(editTitle.trim());
}
setIsEditing(false);
};
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Escape') {
setEditTitle(value);
setIsEditing(false);
} else if (e.key === 'Enter') {
handleTitleSubmit(e);
}
};
const handleSave = (newTitle: string) => {
if (newTitle.trim() && newTitle !== value) {
onChange(newTitle.trim());
}
setIsEditing(false);
};
return (
<div className={cn("min-w-0 flex-1", className)}>
{isMobile && (
<EditSessionTitleDialog
isOpen={isEditing}
currentTitle={value}
onClose={() => setIsEditing(false)}
onSave={handleSave}
/>
)}
{isEditing && !isMobile ? (
<form onSubmit={handleTitleSubmit} className="flex items-center gap-1 min-w-0">
<input
type="text"
value={editTitle}
onChange={(e) => setEditTitle(e.target.value)}
onBlur={(e) => {
if (!e.relatedTarget?.closest('button')) {
handleTitleSubmit(e);
}
}}
onKeyDown={handleKeyDown}
className="text-[16px] sm:text-base font-semibold bg-background border border-border rounded-l px-2 py-1 outline-none w-full truncate focus:border-primary sm:max-w-[250px] h-7"
autoFocus
/>
<Button
type="button"
variant="ghost"
size="icon"
className="h-7 w-7 rounded-l-none border border-l-0 border-border hover:bg-accent flex-shrink-0 mt-0"
onClick={() => setEditTitle("")}
>
<X className="w-3.5 h-3.5" />
</Button>
</form>
) : (
<div className="min-w-0">
{generating ? (
<div className="flex items-center gap-2">
<Loader2 className="w-3 h-3 animate-spin text-muted-foreground" />
<span className="text-xs sm:text-base text-muted-foreground italic">Generating title...</span>
</div>
) : (
<h1
className="text-xs sm:text-base font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate cursor-pointer hover:opacity-80 transition-opacity"
onClick={handleTitleClick}
>
{value}
</h1>
)}
{subtitle && (
<p className="text-[10px] sm:text-xs text-muted-foreground truncate">
{subtitle}
</p>
)}
</div>
)}
</div>
);
}
function HeaderActions({ children, className }: { children: ReactNode; className?: string }) {
return <div className={cn("flex items-center gap-2", className)}>{children}</div>;
}
function HeaderMobileDropdown({ children, className }: { children: ReactNode; className?: string }) {
const isMobile = useMobile();
if (!isMobile) return null;
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="outline"
size="icon"
className={cn("text-foreground border-border hover:bg-accent transition-all duration-200 h-8 w-8", className)}
title="Options"
>
<MoreVertical className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{children}
</DropdownMenuContent>
</DropdownMenu>
);
}
function HeaderSettingsButton() {
const { open: openSettings } = useSettingsDialog();
return (
<Button
variant="ghost"
size="icon"
onClick={openSettings}
className="text-muted-foreground hover:text-foreground hover:bg-accent transition-all duration-200 h-8 w-8"
>
<Settings className="w-4 h-4" />
</Button>
);
}
export const Header = Object.assign(HeaderBase, {
BackButton: HeaderBackButton,
Title: HeaderTitle,
EditableTitle: HeaderEditableTitle,
Actions: HeaderActions,
MobileDropdown: HeaderMobileDropdown,
Settings: HeaderSettingsButton,
}) as typeof HeaderBase & {
BackButton: typeof HeaderBackButton;
Title: typeof HeaderTitle;
EditableTitle: typeof HeaderEditableTitle;
Actions: typeof HeaderActions;
MobileDropdown: typeof HeaderMobileDropdown;
Settings: typeof HeaderSettingsButton;
};
@@ -0,0 +1,80 @@
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { Trash2, Search } from "lucide-react";
interface ListToolbarProps {
searchQuery: string;
onSearchChange: (query: string) => void;
searchPlaceholder?: string;
selectedCount: number;
totalCount: number;
allSelected: boolean;
onToggleSelectAll: () => void;
onDelete: () => void;
onDeleteAll: () => void;
}
export function ListToolbar({
searchQuery,
onSearchChange,
searchPlaceholder = "Search",
selectedCount,
totalCount,
allSelected,
onToggleSelectAll,
onDelete,
onDeleteAll,
}: ListToolbarProps) {
const hasItems = totalCount > 0;
const hasSelection = selectedCount > 0;
const handleMobileDelete = () => {
if (hasSelection) {
onDelete();
} else {
onDeleteAll();
}
};
return (
<div className="flex items-center gap-3">
<div className="relative flex-1">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
<Input
type="text"
placeholder={searchPlaceholder}
value={searchQuery}
onChange={(e) => onSearchChange(e.target.value)}
className="pl-10"
/>
</div>
{hasItems && (
<Button
onClick={onToggleSelectAll}
variant={hasSelection ? "default" : "outline"}
className="whitespace-nowrap hidden md:flex"
>
{allSelected ? "Deselect All" : "Select All"}
</Button>
)}
<Button
onClick={onDelete}
variant="destructive"
disabled={!hasSelection}
className="hidden md:flex whitespace-nowrap"
>
<Trash2 className="w-4 h-4 mr-2" />
Delete ({selectedCount})
</Button>
<Button
onClick={handleMobileDelete}
variant="destructive"
size="icon"
className="md:hidden"
disabled={!hasItems}
>
<Trash2 className="w-4 h-4" />
</Button>
</div>
);
}
@@ -0,0 +1,68 @@
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { PageHeader } from "./page-header";
describe("PageHeader", () => {
it("applies pt-safe class for iOS safe area", () => {
render(<PageHeader data-testid="header">Content</PageHeader>);
const header = screen.getByTestId("header");
expect(header).toHaveClass("pt-safe");
});
it("applies sticky top-0 positioning", () => {
render(<PageHeader data-testid="header">Content</PageHeader>);
const header = screen.getByTestId("header");
expect(header).toHaveClass("sticky");
expect(header).toHaveClass("top-0");
});
it("renders children correctly", () => {
render(
<PageHeader>
<span>Test Child</span>
</PageHeader>
);
expect(screen.getByText("Test Child")).toBeInTheDocument();
});
it("merges custom className", () => {
render(
<PageHeader data-testid="header" className="custom-class">
Content
</PageHeader>
);
const header = screen.getByTestId("header");
expect(header).toHaveClass("custom-class");
expect(header).toHaveClass("pt-safe");
});
it("forwards additional props", () => {
render(
<PageHeader data-testid="header" aria-label="Page header">
Content
</PageHeader>
);
const header = screen.getByTestId("header");
expect(header).toHaveAttribute("aria-label", "Page header");
});
it("applies z-10 for proper stacking", () => {
render(<PageHeader data-testid="header">Content</PageHeader>);
const header = screen.getByTestId("header");
expect(header).toHaveClass("z-10");
});
it("applies background and border styling", () => {
render(<PageHeader data-testid="header">Content</PageHeader>);
const header = screen.getByTestId("header");
expect(header).toHaveClass("border-b");
expect(header).toHaveClass("border-border");
expect(header).toHaveClass("bg-gradient-to-b");
});
it("applies backdrop-blur-sm for frosted glass effect", () => {
render(<PageHeader data-testid="header">Content</PageHeader>);
const header = screen.getByTestId("header");
expect(header).toHaveClass("backdrop-blur-sm");
});
});
@@ -0,0 +1,25 @@
import * as React from "react";
import { cn } from "@/lib/utils";
export interface PageHeaderProps extends React.HTMLAttributes<HTMLElement> {
children: React.ReactNode;
}
export const PageHeader = React.forwardRef<HTMLElement, PageHeaderProps>(
({ className, children, ...props }, ref) => {
return (
<header
ref={ref}
className={cn(
"sticky top-0 z-10 border-b border-border bg-gradient-to-b from-background via-background to-background backdrop-blur-sm pt-safe",
className
)}
{...props}
>
{children}
</header>
);
}
);
PageHeader.displayName = "PageHeader";