Skip to content

A full-featured download manager.

fix(downloads): keep list rows reachable under the inspector drawer (#2288)

a0666660397f1b440254
diff --git a/src/renderer/components/desktop-kit/inspector-drawer.tsx b/src/renderer/components/desktop-kit/inspector-drawer.tsx
index 3c4abaf3..fa2d2d61 100644
--- a/src/renderer/components/desktop-kit/inspector-drawer.tsx
+++ b/src/renderer/components/desktop-kit/inspector-drawer.tsx
@@ -10,7 +10,7 @@ import {
import { type ReactNode, useEffect, useRef, useState } from 'react'
export type InspectorSnap = 'compact' | 'medium' | 'expanded'
-const SNAP_NAMES: InspectorSnap[] = ['compact', 'medium', 'expanded']
+export const SNAP_NAMES: InspectorSnap[] = ['compact', 'medium', 'expanded']
export function getInspectorSnapHeights(availableHeight: number) {
const maximum = Math.max(
diff --git a/src/renderer/components/desktop-kit/panel/panel-shell.tsx b/src/renderer/components/desktop-kit/panel/panel-shell.tsx
index 23d3261a..c998e342 100644
--- a/src/renderer/components/desktop-kit/panel/panel-shell.tsx
+++ b/src/renderer/components/desktop-kit/panel/panel-shell.tsx
@@ -96,7 +96,10 @@ export function PanelShell({
{/* PanelShell footer */}
{footer && (
- <footer className="flex shrink-0 items-center justify-between gap-2 px-6 py-3">
+ <footer
+ data-slot="panel-shell-footer"
+ className="flex shrink-0 items-center justify-between gap-2 px-6 py-3"
+ >
{footer}
</footer>
)}
diff --git a/src/renderer/components/desktop-kit/virtual-list/types.ts b/src/renderer/components/desktop-kit/virtual-list/types.ts
index 8e40bb8b..e47a9a53 100644
--- a/src/renderer/components/desktop-kit/virtual-list/types.ts
+++ b/src/renderer/components/desktop-kit/virtual-list/types.ts
@@ -14,6 +14,9 @@ export interface VirtualListProps<T> {
renderRow: (props: RowRenderProps<T>) => ReactNode
renderHeader?: () => ReactNode
renderEmpty?: () => ReactNode
+ /** Scroll space appended below the last row so an overlaying element (such
+ * as the inspector drawer) never traps rows out of reach. */
+ bottomInset?: number
className?: string
style?: CSSProperties
/** Keep the active descendant mounted outside the visible range. */
diff --git a/src/renderer/components/desktop-kit/virtual-list/virtual-list.test.tsx b/src/renderer/components/desktop-kit/virtual-list/virtual-list.test.tsx
index 1969aa8d..ead3be8d 100644
--- a/src/renderer/components/desktop-kit/virtual-list/virtual-list.test.tsx
+++ b/src/renderer/components/desktop-kit/virtual-list/virtual-list.test.tsx
@@ -74,6 +74,39 @@ describe('VirtualList', () => {
expect(scrollContainer).not.toBeNull()
})
+ it('appends the bottom inset as scroll space after the last row', () => {
+ const { container } = render(
+ <VirtualList<TestItem>
+ items={makeItems(10)}
+ getId={(item) => item.id}
+ rowHeight={40}
+ bottomInset={220}
+ renderRow={({ item }) => <div>{item.label}</div>}
+ />
+ )
+ const scrollContainer = container.querySelector(
+ '[data-testid="virtual-list-container"]'
+ ) as HTMLElement
+ const spacer = scrollContainer.lastElementChild as HTMLElement
+ expect(spacer.getAttribute('aria-hidden')).toBe('true')
+ expect(spacer.style.height).toBe('220px')
+ })
+
+ it('omits bottom inset scroll space when zero', () => {
+ const { container } = render(
+ <VirtualList<TestItem>
+ items={makeItems(10)}
+ getId={(item) => item.id}
+ rowHeight={40}
+ renderRow={({ item }) => <div>{item.label}</div>}
+ />
+ )
+ const scrollContainer = container.querySelector(
+ '[data-testid="virtual-list-container"]'
+ ) as HTMLElement
+ expect(scrollContainer.querySelector('[aria-hidden="true"]')).toBeNull()
+ })
+
it.each(['native', 'custom'] as const)(
'retains active options and viewport semantics with %s scrollbars',
(scrollbar) => {
diff --git a/src/renderer/components/desktop-kit/virtual-list/virtual-list.tsx b/src/renderer/components/desktop-kit/virtual-list/virtual-list.tsx
index 9355864d..ddb0c6c4 100644
--- a/src/renderer/components/desktop-kit/virtual-list/virtual-list.tsx
+++ b/src/renderer/components/desktop-kit/virtual-list/virtual-list.tsx
@@ -33,6 +33,7 @@ function VirtualListInner<T>(
keepMountedIndex,
scrollbar = 'native',
scrollRef,
+ bottomInset = 0,
renderRow,
renderHeader,
renderEmpty,
@@ -71,6 +72,7 @@ function VirtualListInner<T>(
getItemKey,
scrollMargin: headerHeight,
scrollPaddingStart: headerHeight,
+ scrollPaddingEnd: bottomInset,
getScrollElement: () => containerRef.current,
estimateSize: () => rowHeight,
overscan,
@@ -130,6 +132,12 @@ function VirtualListInner<T>(
})}
</div>
)}
+ {bottomInset > 0 ? (
+ <div
+ aria-hidden="true"
+ style={{ height: bottomInset, width: '100%' }}
+ />
+ ) : null}
</>
)
diff --git a/src/renderer/routes/downloads/downloads-page.tsx b/src/renderer/routes/downloads/downloads-page.tsx
index 9bcf7396..d3e6fa5f 100644
--- a/src/renderer/routes/downloads/downloads-page.tsx
+++ b/src/renderer/routes/downloads/downloads-page.tsx
@@ -32,6 +32,7 @@ import {
taskMatchesTab,
} from './filter'
import { GlobalStatsBar } from './global-stats-bar'
+import { resolveInspectorInset } from './inspector-inset'
import { StatusTitleMenu } from './status-title-menu'
import { useDownloadsSelection } from './store'
import { TaskInspectorDrawer } from './task-inspector-drawer'
@@ -285,6 +286,66 @@ export function DownloadsPage() {
])
const [container, setContainer] = useState<HTMLElement | null>(null)
+
+ // The inspector drawer overlays the page root without resizing the list, so
+ // the list must reserve scroll space for the band the drawer covers;
+ // otherwise rows in that band (typically the active ones, sorted last) can
+ // never scroll above the drawer's top edge.
+ const inspectorVisible = useDownloadsView((state) => state.inspectorVisible)
+ const inspectorSnap = useDownloadsView((state) => state.inspectorSnap)
+ const committedIds = useDownloadsSelection(
+ (state) => state.committedSelectedIds
+ )
+ // Mirror useTaskInspectorState's open condition so scroll space is only
+ // reserved while the drawer actually overlays the page.
+ const inspectorOpen = useMemo(
+ () =>
+ inspectorVisible &&
+ tasks.some(
+ (task) => committedIds.has(task.id) && isTaskAvailable(task.status)
+ ),
+ [committedIds, inspectorVisible, tasks]
+ )
+ const [inspectorMetrics, setInspectorMetrics] = useState({
+ page: 0,
+ footer: 0,
+ grid: 0,
+ })
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the list swaps between skeleton, grid, and empty states without resizing the page root; re-running re-queries the footer and grid elements
+ useEffect(() => {
+ if (!container) return
+ const measure = () => {
+ const page = container.getBoundingClientRect().height
+ const footer =
+ container
+ .querySelector<HTMLElement>('[data-slot="panel-shell-footer"]')
+ ?.getBoundingClientRect().height ?? 0
+ const grid =
+ container
+ .querySelector<HTMLElement>('[data-downloads-grid]')
+ ?.getBoundingClientRect().height ?? 0
+ setInspectorMetrics((previous) =>
+ previous.page === page &&
+ previous.footer === footer &&
+ previous.grid === grid
+ ? previous
+ : { page, footer, grid }
+ )
+ }
+ measure()
+ if (typeof ResizeObserver === 'undefined') return
+ const observer = new ResizeObserver(measure)
+ observer.observe(container)
+ return () => observer.disconnect()
+ }, [container, status, hasReadySnapshot, filtered.length])
+ const inspectorInset = resolveInspectorInset({
+ pageHeight: inspectorMetrics.page,
+ footerHeight: inspectorMetrics.footer,
+ gridHeight: inspectorMetrics.grid,
+ snap: inspectorSnap,
+ open: inspectorOpen,
+ })
+
const taskList =
status === 'loading' && !hasReadySnapshot ? (
<TaskListSkeleton />
@@ -299,6 +360,7 @@ export function DownloadsPage() {
filter={filter}
search={query}
onClearSearch={() => onQueryChange('')}
+ bottomInset={inspectorInset}
/>
)
diff --git a/src/renderer/routes/downloads/inspector-inset.test.ts b/src/renderer/routes/downloads/inspector-inset.test.ts
new file mode 100644
index 00000000..23239a8d
--- /dev/null
+++ b/src/renderer/routes/downloads/inspector-inset.test.ts
@@ -0,0 +1,90 @@
+import { describe, expect, it } from 'vitest'
+import { resolveInspectorInset } from './inspector-inset'
+
+const FOOTER = 48
+const HEADER = 80
+
+describe('resolveInspectorInset', () => {
+ it('returns 0 when the inspector is closed', () => {
+ expect(
+ resolveInspectorInset({
+ pageHeight: 800,
+ footerHeight: FOOTER,
+ gridHeight: 800 - HEADER - FOOTER,
+ snap: 'medium',
+ open: false,
+ })
+ ).toBe(0)
+ })
+
+ it('returns 0 before the page has been measured', () => {
+ expect(
+ resolveInspectorInset({
+ pageHeight: 0,
+ footerHeight: 0,
+ gridHeight: 0,
+ snap: 'medium',
+ open: true,
+ })
+ ).toBe(0)
+ })
+
+ it('compensates the overlap above the overlaid footer for each snap', () => {
+ const base = {
+ pageHeight: 800,
+ footerHeight: FOOTER,
+ gridHeight: 800 - HEADER - FOOTER,
+ open: true,
+ }
+ // getInspectorSnapHeights(800) resolves to [220, 400, 600].
+ expect(resolveInspectorInset({ ...base, snap: 'compact' })).toBe(
+ 220 - FOOTER
+ )
+ expect(resolveInspectorInset({ ...base, snap: 'medium' })).toBe(
+ 400 - FOOTER
+ )
+ expect(resolveInspectorInset({ ...base, snap: 'expanded' })).toBe(
+ 600 - FOOTER
+ )
+ })
+
+ it('ignores a drawer that does not reach past the footer', () => {
+ expect(
+ resolveInspectorInset({
+ pageHeight: 96,
+ footerHeight: FOOTER,
+ gridHeight: 10,
+ snap: 'compact',
+ open: true,
+ })
+ ).toBe(0)
+ })
+
+ it('never scrolls the last row out of the grid on short pages', () => {
+ // On a 200px page every snap merges at 136px; the 72px grid leaves no
+ // room once the header and one row are excluded.
+ expect(
+ resolveInspectorInset({
+ pageHeight: 200,
+ footerHeight: FOOTER,
+ gridHeight: 200 - HEADER - FOOTER,
+ snap: 'medium',
+ open: true,
+ })
+ ).toBe(0)
+ })
+
+ it('caps compensation so the last row stays reachable', () => {
+ // Expanded on a 300px page: maximum is 225px, overlap 177px, but the
+ // 172px grid only offsets rows by 100px before they leave the top.
+ expect(
+ resolveInspectorInset({
+ pageHeight: 300,
+ footerHeight: FOOTER,
+ gridHeight: 300 - HEADER - FOOTER,
+ snap: 'expanded',
+ open: true,
+ })
+ ).toBe(300 - HEADER - FOOTER - 36 - 36)
+ })
+})
diff --git a/src/renderer/routes/downloads/inspector-inset.ts b/src/renderer/routes/downloads/inspector-inset.ts
new file mode 100644
index 00000000..5cc4fa40
--- /dev/null
+++ b/src/renderer/routes/downloads/inspector-inset.ts
@@ -0,0 +1,45 @@
+import {
+ getInspectorSnapHeights,
+ type InspectorSnap,
+ SNAP_NAMES,
+} from '@renderer/components/desktop-kit/inspector-drawer'
+import { TASK_HEADER_HEIGHT, TASK_ROW_HEIGHT } from './columns'
+
+export interface InspectorInsetInput {
+ /** Height of the portal container the drawer overlays (the page root). */
+ pageHeight: number
+ /** Height of the PanelShell footer, which the drawer also overlays. */
+ footerHeight: number
+ /** Height of the task grid wrapper that owns the scroll region. */
+ gridHeight: number
+ snap: InspectorSnap
+ open: boolean
+}
+
+/**
+ * Scroll space the task list must append below its last row while the
+ * inspector drawer is open. The drawer floats over the page without resizing
+ * the list, so without compensation the rows inside the covered band can
+ * never scroll above the drawer's top edge. The overlaid footer needs no
+ * reachability of its own, so only the overlap above it is compensated.
+ */
+export function resolveInspectorInset({
+ pageHeight,
+ footerHeight,
+ gridHeight,
+ snap,
+ open,
+}: InspectorInsetInput): number {
+ if (!open || pageHeight <= 0) return 0
+ const snapIndex = SNAP_NAMES.indexOf(snap)
+ const drawerHeight =
+ getInspectorSnapHeights(pageHeight)[
+ snapIndex === -1 ? SNAP_NAMES.length - 1 : snapIndex
+ ]
+ const overlap = Math.max(0, drawerHeight - footerHeight)
+ // A drawer tall enough to swallow nearly the whole grid must not push rows
+ // out of reach in the other direction: cap the compensation so the last row
+ // stays visible at the top of the scroll region.
+ const limit = Math.max(0, gridHeight - TASK_HEADER_HEIGHT - TASK_ROW_HEIGHT)
+ return Math.min(overlap, limit)
+}
diff --git a/src/renderer/routes/downloads/task-list-panel.tsx b/src/renderer/routes/downloads/task-list-panel.tsx
index 1977386d..1ff46174 100644
--- a/src/renderer/routes/downloads/task-list-panel.tsx
+++ b/src/renderer/routes/downloads/task-list-panel.tsx
@@ -30,6 +30,9 @@ export interface TaskListPanelProps {
filter: DownloadsTab
search: string
onClearSearch: () => void
+ /** Scroll space appended below the last row so the overlaying inspector
+ * drawer never traps rows out of reach. */
+ bottomInset?: number
}
export function TaskListPanel({
@@ -39,6 +42,7 @@ export function TaskListPanel({
filter,
search,
onClearSearch,
+ bottomInset = 0,
}: TaskListPanelProps) {
const { t, i18n } = useTranslation()
const sort = useDownloadsSort((state) => state.sort)
@@ -292,6 +296,7 @@ export function TaskListPanel({
ref={listRef}
{...listProps}
scrollbar="custom"
+ bottomInset={bottomInset}
keepMountedIndex={
focusedId
? displayed.findIndex((task) => task.id === focusedId)