Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

refactor(webv2): give Scrollable an orientation and drop hand-rolled scroll areas

joshistoast8ddc066c774c
diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/BundleChips.browser.test.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/BundleChips.browser.test.tsx
new file mode 100644
index 0000000000..573e2d9411
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/BundleChips.browser.test.tsx
@@ -0,0 +1,87 @@
+/* oxlint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-function-as-prop */
+import type { StarterModel, StarterModelBundle } from '@features/models/core/types';
+
+import { Box, ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { BundleChips } from './BundleChips';
+
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+
+const makeModel = (name: string): StarterModel => ({
+ base: 'sdxl',
+ description: '',
+ dependencies: null,
+ format: 'checkpoint',
+ is_installed: false,
+ name,
+ source: `https://example.test/${name}`,
+ type: 'main',
+});
+
+// A dozen long bundle names guarantee the row overflows a narrow host no
+// matter what font metrics the browser resolves.
+const bundles: StarterModelBundle[] = Array.from({ length: 12 }, (_, index) => ({
+ models: [makeModel(`model-${index}`)],
+ name: `Very Long Bundle Name ${index}`,
+}));
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+describe('BundleChips overflow', () => {
+ let host: HTMLDivElement;
+ let root: Root;
+
+ beforeEach(() => {
+ host = document.createElement('div');
+ host.style.cssText = 'width:240px;';
+ document.body.append(host);
+ root = createRoot(host);
+ });
+
+ afterEach(async () => {
+ await act(() => root.unmount());
+ host.remove();
+ });
+
+ it('scrolls the chip row horizontally and keeps trailing content outside the scroll region', async () => {
+ await act(async () => {
+ root.render(
+ <ChakraProvider value={system}>
+ <BundleChips
+ bundles={bundles}
+ selectedName={null}
+ starterCount={40}
+ trailing={<Box data-testid="trailing-marker">trailing</Box>}
+ onSelect={() => undefined}
+ />
+ </ChakraProvider>
+ );
+ await Promise.resolve();
+ });
+
+ const viewport = host.querySelector<HTMLElement>('[data-scope="scroll-area"][data-part="viewport"]');
+ const horizontalScrollbar = host.querySelector<HTMLElement>(
+ '[data-scope="scroll-area"][data-part="scrollbar"][data-orientation="horizontal"]'
+ );
+ const trailing = host.querySelector<HTMLElement>('[data-testid="trailing-marker"]');
+
+ expect(viewport).not.toBeNull();
+ expect(horizontalScrollbar).not.toBeNull();
+ expect(trailing).not.toBeNull();
+
+ // (a) the chip row overflows the viewport horizontally.
+ expect(viewport!.scrollWidth).toBeGreaterThan(viewport!.clientWidth);
+
+ // (b) a horizontal scrollbar part is rendered (asserted above via the
+ // non-null query; also confirm zag hasn't hidden it via data attrs).
+ expect(horizontalScrollbar!.getAttribute('data-orientation')).toBe('horizontal');
+
+ // (c) the trailing element is not part of the scrolling content — it
+ // lives outside the viewport entirely, so it never scrolls with the chips.
+ expect(viewport!.contains(trailing)).toBe(false);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/BundleChips.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/BundleChips.tsx
index 3080a3ebf6..77fdd30ad7 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/BundleChips.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/BundleChips.tsx
@@ -2,8 +2,9 @@
import type { StarterModelBundle } from '@features/models/core/types';
import type { ReactNode } from 'react';
-import { Badge, Box, HStack, Icon, ScrollArea } from '@chakra-ui/react';
+import { Badge, Box, HStack, Icon } from '@chakra-ui/react';
import { Button } from '@platform/ui';
+import { Scrollable } from '@platform/ui/Scrollable';
import { CheckIcon, FolderIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
@@ -30,37 +31,37 @@ export const BundleChips = ({
return (
<HStack align="center" gap="2" minW="0" px="3" pb="1">
{bundles.length > 0 ? (
- <ScrollArea.Root flex="1" minW="0" size="xs" variant="hover">
- <ScrollArea.Viewport w="full">
- <ScrollArea.Content asChild>
- <HStack gap="1.5">
+ <Scrollable
+ flex="1"
+ label={t('modelManager.launchpad.starterBundles')}
+ minW="0"
+ orientation="horizontal"
+ size="xs"
+ variant="hover"
+ >
+ <HStack gap="1.5">
+ <BundleChip
+ isSelected={selectedName === null}
+ label={t('common.all')}
+ subLabel={`${starterCount}`}
+ onSelect={() => onSelect(null)}
+ />
+ {bundles.map((bundle) => {
+ const missingCount = bundle.models.filter((model) => !model.is_installed).length;
+
+ return (
<BundleChip
- isSelected={selectedName === null}
- label={t('common.all')}
- subLabel={`${starterCount}`}
- onSelect={() => onSelect(null)}
+ key={bundle.name}
+ isComplete={missingCount === 0}
+ isSelected={selectedName === bundle.name}
+ label={bundle.name}
+ subLabel={`${bundle.models.length}`}
+ onSelect={() => onSelect(bundle.name)}
/>
- {bundles.map((bundle) => {
- const missingCount = bundle.models.filter((model) => !model.is_installed).length;
-
- return (
- <BundleChip
- key={bundle.name}
- isComplete={missingCount === 0}
- isSelected={selectedName === bundle.name}
- label={bundle.name}
- subLabel={`${bundle.models.length}`}
- onSelect={() => onSelect(bundle.name)}
- />
- );
- })}
- </HStack>
- </ScrollArea.Content>
- </ScrollArea.Viewport>
- <ScrollArea.Scrollbar orientation="horizontal">
- <ScrollArea.Thumb />
- </ScrollArea.Scrollbar>
- </ScrollArea.Root>
+ );
+ })}
+ </HStack>
+ </Scrollable>
) : (
<Box flex="1" minW="0" />
)}
diff --git a/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx b/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx
index 1b175729b5..cf86c670da 100644
--- a/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx
@@ -14,6 +14,7 @@ export const Scrollable = ({
children,
contentProps,
label,
+ orientation = 'vertical',
viewportRef,
...rootProps
}: ScrollAreaRootProps & {
@@ -22,16 +23,18 @@ export const Scrollable = ({
contentProps?: ScrollAreaContentProps;
/** Accessible name for the scroll viewport. */
label?: string;
+ /** Scroll axis; the scrollbar and content sizing follow it. Defaults to vertical. */
+ orientation?: 'horizontal' | 'vertical';
/** The scrolling element itself — what a virtualizer needs to observe. */
viewportRef?: Ref<HTMLDivElement>;
}) => (
<ScrollArea.Root size="xs" variant="hover" {...rootProps}>
<ScrollArea.Viewport aria-label={label} h="full" ref={viewportRef} role={label ? 'region' : undefined} w="full">
- <ScrollArea.Content w="full" {...contentProps}>
+ <ScrollArea.Content w={orientation === 'horizontal' ? 'max-content' : 'full'} {...contentProps}>
{children}
</ScrollArea.Content>
</ScrollArea.Viewport>
- <ScrollArea.Scrollbar>
+ <ScrollArea.Scrollbar orientation={orientation}>
<ScrollArea.Thumb />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
index 7a80a74300..673395ffa0 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
@@ -1,9 +1,10 @@
import type { GalleryItem, GalleryItemKey } from '@features/gallery';
-import { Box, HStack, ScrollArea } from '@chakra-ui/react';
+import { Box, HStack } from '@chakra-ui/react';
import { useDraggable } from '@dnd-kit/core';
import { toGalleryItemKey, toGalleryItemRef } from '@features/gallery/contracts';
import { getGalleryItemDragData, getGalleryItemDragId } from '@features/gallery/utility';
+import { Scrollable } from '@platform/ui/Scrollable';
import { useCallback, useMemo } from 'react';
import type { PreviewDensity } from './previewDensity';
@@ -42,44 +43,37 @@ export const PreviewFilmstrip = ({
// intrinsic width so a long board can never stretch the widget wider than
// its panel (side panels host widgets in a grid ScrollArea.Content that
// otherwise grows to max-content).
- <ScrollArea.Root
+ <Scrollable
bg="bg.subtle"
borderColor="border.subtle"
borderWidth="1px"
+ contentProps={FILMSTRIP_CONTENT_PROPS}
css={FILMSTRIP_CONTAIN_CSS}
flexShrink={0}
h={density === 'full' ? '3.75rem' : '2.75rem'}
minW="0"
+ orientation="horizontal"
px="1.5"
rounded="md"
shadow="sm"
- size="xs"
- variant="hover"
w="full"
>
- <ScrollArea.Viewport h="full" w="full">
- <ScrollArea.Content asChild>
- <HStack align="center" gap="1" h="full">
- {items.map((item) => {
- const itemKey = toGalleryItemKey(item);
+ <HStack align="center" gap="1" h="full">
+ {items.map((item) => {
+ const itemKey = toGalleryItemKey(item);
- return (
- <FilmstripThumb
- key={itemKey}
- item={item}
- isSelected={itemKey === selectedItemKey}
- size={thumbSize}
- onSelect={onSelect}
- />
- );
- })}
- </HStack>
- </ScrollArea.Content>
- </ScrollArea.Viewport>
- <ScrollArea.Scrollbar orientation="horizontal">
- <ScrollArea.Thumb />
- </ScrollArea.Scrollbar>
- </ScrollArea.Root>
+ return (
+ <FilmstripThumb
+ key={itemKey}
+ item={item}
+ isSelected={itemKey === selectedItemKey}
+ size={thumbSize}
+ onSelect={onSelect}
+ />
+ );
+ })}
+ </HStack>
+ </Scrollable>
);
};
@@ -144,6 +138,10 @@ const FilmstripThumb = ({
const FILMSTRIP_CONTAIN_CSS = { contain: 'inline-size' } as const;
+// The thumb row centers itself with `h="full"`, which needs the content
+// wrapper to actually span the viewport height rather than shrink to it.
+const FILMSTRIP_CONTENT_PROPS = { h: 'full' } as const;
+
const FILMSTRIP_IMG_STYLE = {
display: 'block',
height: '100%',
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx
index 9e57a10877..a527e1614f 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx
@@ -202,6 +202,36 @@ describe('PreviewFilmstrip mixed media', () => {
expect(selected.querySelector(':scope > div')).toBeNull();
});
+ it('vertically centers the thumb row inside the fixed-height scroll viewport', async () => {
+ await render(
+ <DndContext>
+ <PreviewFilmstrip
+ density="full"
+ items={[sharedImage, sharedVideo]}
+ selectedItemKey="image:shared"
+ onSelect={() => undefined}
+ />
+ </DndContext>
+ );
+
+ const viewport = host!.querySelector<HTMLElement>('[data-scope="scroll-area"][data-part="viewport"]');
+ const thumb = host!.querySelector<HTMLButtonElement>('[aria-current="true"]');
+
+ expect(viewport).not.toBeNull();
+ expect(thumb).not.toBeNull();
+
+ const viewportRect = viewport!.getBoundingClientRect();
+ const thumbRect = thumb!.getBoundingClientRect();
+ const viewportCenterY = viewportRect.top + viewportRect.height / 2;
+ const thumbCenterY = thumbRect.top + thumbRect.height / 2;
+
+ // Without the Scrollable `contentProps={{ h: 'full' }}` fix, the content
+ // wrapper shrinks to the thumb row's own height and the row sticks to
+ // the viewport's top edge instead of centering in it — a multi-pixel
+ // offset for the "full" density's 60px strip / 48px thumb combination.
+ expect(Math.abs(thumbCenterY - viewportCenterY)).toBeLessThan(1);
+ });
+
it('keeps same-name media independent and selects the clicked video poster', async () => {
const onSelect = vi.fn();