Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions components/object/preview-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -457,34 +457,26 @@ export function ObjectPreviewModal({ show, onShowChange, onDownload, object }: O
} as React.CSSProperties
}
>
<DialogHeader className="flex-row items-start justify-between gap-2 pe-12 [@media(hover:hover)_and_(pointer:fine)]:pe-8">
<DialogTitle>{t("Preview")}</DialogTitle>
<DialogHeader className="min-w-0 pe-28 sm:pe-24">
<DialogTitle className="min-w-0 [overflow-wrap:anywhere]">{t("Preview")}</DialogTitle>
</DialogHeader>
<div className="absolute end-4 top-4 flex items-center gap-1">
<Button
type="button"
variant="ghost"
size="icon-sm"
className="shrink-0"
aria-label={isDialogExpanded ? t("Collapse") : t("Expand")}
title={isDialogExpanded ? t("Collapse") : t("Expand")}
onClick={() => setIsDialogExpanded((expanded) => !expanded)}
>
{isDialogExpanded ? <RiFullscreenExitLine aria-hidden /> : <RiFullscreenLine aria-hidden />}
</Button>
</DialogHeader>
<DialogClose
render={
<Button
type="button"
variant="ghost"
size="icon-sm"
className="absolute end-2 top-2"
aria-label={t("Close")}
title={t("Close")}
/>
}
>
<RiCloseLine aria-hidden />
</DialogClose>
<DialogClose
render={<Button type="button" variant="ghost" size="icon-sm" aria-label={t("Close")} title={t("Close")} />}
>
<RiCloseLine aria-hidden />
</DialogClose>
</div>
<div className="flex min-h-0 min-w-0 flex-col overflow-hidden border p-4">{renderPreview()}</div>
</DialogContent>
</Dialog>
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/object-preview-source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ test("object preview dialog provides a keyboard-operable expand and collapse alt
assert.match(source, /"--preview-dialog-width": "min\(56rem, calc\(100vw - 2rem\)\)"/)
})

test("object preview dialog places Expand next to Close instead of underneath it", () => {
const source = fs.readFileSync("components/object/preview-modal.tsx", "utf8")

assert.match(
source,
/<div className="absolute end-4 top-4 flex items-center gap-1">\s*<Button[\s\S]*?t\("Expand"\)[\s\S]*?<\/Button>\s*<DialogClose/,
)
assert.doesNotMatch(source, /<DialogHeader[^>]*>\s*<DialogTitle[^>]*>\{t\("Preview"\)\}<\/DialogTitle>\s*<Button/)
})

test("object preview reserves enough mobile header space for both touch controls", () => {
const source = fs.readFileSync("components/object/preview-modal.tsx", "utf8")
const headerClasses = source.match(/<DialogHeader className="([^"]+)"/)?.[1] ?? ""
const endPadding = Number(headerClasses.match(/(?:^|\s)pe-(\d+)(?:\s|$)/)?.[1]) * 4

// Two 44px touch targets, their 4px gap, and the 16px end offset must fit beside the title.
assert.ok(endPadding >= 44 * 2 + 4 + 16)
assert.match(source, /<DialogTitle className="[^"]*min-w-0[^"]*\[overflow-wrap:anywhere\][^"]*"/)
})

test("object preview dialog keeps compact preview modes at a compact default height", () => {
const source = fs.readFileSync("components/object/preview-modal.tsx", "utf8")

Expand Down