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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): preserve gallery accessibility after upstream sync
joshistoast1ff515b0bf64
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsxindex 832b42997f..0344d07ed4 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx@@ -3,7 +3,7 @@ import type { GalleryItem, GalleryItemRef } from '@features/gallery/contracts';import type { GalleryItemsFilter } from '@features/gallery/data/queries';import type { StreamingImageSource } from '@platform/ui/streaming-image/streamingImageSource';-import { ChakraProvider } from '@chakra-ui/react';+import { Box, ChakraProvider } from '@chakra-ui/react';import {DndContext,KeyboardSensor,@@ -19,6 +19,7 @@ import { GalleryUiProvider, type GalleryUiAdapter } from '@features/gallery/reacimport { isGalleryImageDragData } from '@features/gallery/utility';import { parseDateTokens } from '@platform/search/dateTokens';import { accountLifecycle } from '@platform/state/accountLifecycle';+import { getContrastRatio } from '@platform/ui/theme/contrastRatio.testing';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { system } from '@theme/system';import { PreviewFilmstrip } from '@workbench/widgets/preview/PreviewFilmstrip';@@ -346,9 +347,11 @@ const DragMonitor = () => {};const Harness = ({+ background = 'bg',coMountPreviewSources = false,gallery,}: {+ background?: 'bg' | 'bg.panel';coMountPreviewSources?: boolean;gallery: GalleryStateView;}) => {@@ -375,7 +378,9 @@ const Harness = ({<GalleryWidgetContext value={contextValue}><DndContext sensors={sensors}><DragMonitor />- <GalleryImageGrid />+ <Box bg={background} data-testid="gallery-surface" h="full">+ <GalleryImageGrid />+ </Box>{coMountPreviewSources ? (<><PreviewFrame@@ -412,9 +417,15 @@ const interact = (action: () => void, delay = 0): Promise<void> =>});});-const renderGallery = async (gallery = currentGallery, coMountPreviewSources = false) => {+const renderGallery = async (+ gallery = currentGallery,+ coMountPreviewSources = false,+ background: 'bg' | 'bg.panel' = 'bg'+) => {currentGallery = gallery;- await interact(() => root?.render(<Harness coMountPreviewSources={coMountPreviewSources} gallery={gallery} />));+ await interact(() =>+ root?.render(<Harness background={background} coMountPreviewSources={coMountPreviewSources} gallery={gallery} />)+ );};const getButton = (label: string): HTMLButtonElement => {@@ -472,6 +483,7 @@ describe('GalleryImageGrid mixed item cells', () => {expect(trigger.getAttribute('aria-expanded')).toBe('true');expect(trigger.textContent).toContain('Starred');+ expect(trigger.closest('[role="list"]')).toBeNull();expect(starredSection?.querySelector('button[aria-label="Select starred.png for preview"]')).not.toBeNull();expect(regularSection?.querySelector('button[aria-label="Select regular.png for preview"]')).not.toBeNull();expect(@@ -481,6 +493,33 @@ describe('GalleryImageGrid mixed item cells', () => {).toEqual(['starred', 'regular']);});+ it.each(['bg', 'bg.panel'] as const)('keeps the starred count readable on the %s surface', async (background) => {+ await renderGallery(+ createGallery({+ items: [createItem('image', 'starred.png', { starred: true }), createItem('image', 'regular.png')],+ }),+ false,+ background+ );++ const trigger = getButton('Collapse starred items');+ const count = [...trigger.querySelectorAll<HTMLElement>('span')].find((span) => span.textContent === '1');+ const surface = host?.querySelector<HTMLElement>('[data-testid="gallery-surface"]');++ if (!count || !surface) {+ throw new Error('Expected the starred count and gallery surface');+ }++ const countStyle = getComputedStyle(count);+ const ratio = getContrastRatio(+ countStyle.color,+ getComputedStyle(surface).backgroundColor,+ Number(countStyle.opacity)+ );++ expect(ratio).toBeGreaterThanOrEqual(4.5);+ });+it('matches board disclosure chrome while retaining the star marker', async () => {await renderGallery(createGallery({diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsxindex 8db1ca9968..b8dd914821 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx@@ -69,6 +69,7 @@ const GalleryStarredSectionHeader = ({top="0"transform={`translateY(${offsetPx}px)`}w="full"+ zIndex="1"><chakra.buttonaria-expanded={isOpen}@@ -104,7 +105,7 @@ const GalleryStarredSectionHeader = ({>{t('widgets.gallery.starredItems')}</Text>- <Text as="span" color="fg.subtle" fontSize="2xs" fontVariantNumeric="tabular-nums" lineHeight="1">+ <Text as="span" color="currentColor" fontSize="2xs" fontVariantNumeric="tabular-nums" lineHeight="1">{itemCount}</Text></HStack>@@ -373,80 +374,90 @@ export const GalleryImageGrid = () => {) : (<ScrollArea.Root h="full" minH="0" size="xs" variant="hover" w="full"><ScrollArea.Viewport ref={viewportRef} h="full" outline="none" w="full">- <ScrollArea.Content aria-label={t('widgets.gallery.itemsAriaLabel')} role="list">+ <ScrollArea.Content><Box h={`${virtualizer.totalSize}px`} position="relative" w="full">{virtualRows.map((virtualRow) => {const row = rows[virtualRow.index];- if (!row || row.kind === 'starred-gap') {- return null;- }+ return row?.kind === 'starred-header' ? (+ <GalleryStarredSectionHeader+ key={virtualRow.key}+ isOpen={isStarredOpen}+ itemCount={row.itemCount}+ offsetPx={virtualRow.start}+ onToggle={handleToggleStarredSection}+ />+ ) : null;+ })}+ <Box+ aria-label={t('widgets.gallery.itemsAriaLabel')}+ h="full"+ inset="0"+ position="absolute"+ role="list"+ w="full"+ >+ {virtualRows.map((virtualRow) => {+ const row = rows[virtualRow.index];++ if (!row || row.kind === 'starred-gap' || row.kind === 'starred-header') {+ return null;+ }- if (row.kind === 'starred-header') {return (- <GalleryStarredSectionHeader+ <Boxkey={virtualRow.key}- isOpen={isStarredOpen}- itemCount={row.itemCount}- offsetPx={virtualRow.start}- onToggle={handleToggleStarredSection}- />+ data-gallery-section={row.section}+ display="grid"+ gap={`${GALLERY_GRID_GAP_PX}px`}+ gridTemplateColumns={`repeat(${columnCount}, minmax(0, 1fr))`}+ left="0"+ position="absolute"+ role="presentation"+ top="0"+ transform={`translateY(${virtualRow.start}px)`}+ w="full"+ >+ {row.cells.map((cell) =>+ cell.kind === 'placeholder' ? (+ <GalleryQueuePlaceholderCell+ key={cell.placeholder.id}+ antialiasProgressImages={antialiasProgressImages}+ fit={thumbnailFit}+ isSelected={+ gallery.currentItem?.kind === 'placeholder' &&+ gallery.currentItem.placeholder.id === cell.placeholder.id+ }+ placeholder={cell.placeholder}+ onClick={handleShowProgressImages}+ />+ ) : (+ <GalleryThumbnailCell+ key={toGalleryItemKey(cell.item)}+ alwaysShowDimensions={showImageDimensions}+ dragScope={region}+ compareRole={+ isComparisonActive && toGalleryItemKey(cell.item) === gallery.selectedItemKey+ ? t('widgets.preview.viewing')+ : isComparisonActive && toGalleryItemKey(cell.item) === gallery.compareImageKey+ ? t('widgets.preview.compare')+ : null+ }+ fit={thumbnailFit}+ getDragItems={getDragItems}+ isPrimary={!isFollowingLive && toGalleryItemKey(cell.item) === gallery.selectedItemKey}+ isSelected={!isFollowingLive && selectedItemKeys.has(toGalleryItemKey(cell.item))}+ item={cell.item}+ onClick={handleThumbnailClick}+ onContextMenu={handleThumbnailContextMenu}+ onToggleStarred={handleToggleStarred}+ />+ )+ )}+ </Box>);- }-- return (- <Box- key={virtualRow.key}- data-gallery-section={row.section}- display="grid"- gap={`${GALLERY_GRID_GAP_PX}px`}- gridTemplateColumns={`repeat(${columnCount}, minmax(0, 1fr))`}- left="0"- position="absolute"- role="presentation"- top="0"- transform={`translateY(${virtualRow.start}px)`}- w="full"- >- {row.cells.map((cell) =>- cell.kind === 'placeholder' ? (- <GalleryQueuePlaceholderCell- key={cell.placeholder.id}- antialiasProgressImages={antialiasProgressImages}- fit={thumbnailFit}- isSelected={- gallery.currentItem?.kind === 'placeholder' &&- gallery.currentItem.placeholder.id === cell.placeholder.id- }- placeholder={cell.placeholder}- onClick={handleShowProgressImages}- />- ) : (- <GalleryThumbnailCell- key={toGalleryItemKey(cell.item)}- alwaysShowDimensions={showImageDimensions}- dragScope={region}- compareRole={- isComparisonActive && toGalleryItemKey(cell.item) === gallery.selectedItemKey- ? t('widgets.preview.viewing')- : isComparisonActive && toGalleryItemKey(cell.item) === gallery.compareImageKey- ? t('widgets.preview.compare')- : null- }- fit={thumbnailFit}- getDragItems={getDragItems}- isPrimary={!isFollowingLive && toGalleryItemKey(cell.item) === gallery.selectedItemKey}- isSelected={!isFollowingLive && selectedItemKeys.has(toGalleryItemKey(cell.item))}- item={cell.item}- onClick={handleThumbnailClick}- onContextMenu={handleThumbnailContextMenu}- onToggleStarred={handleToggleStarred}- />- )- )}- </Box>- );- })}+ })}+ </Box></Box>{paginationMode === 'infinite' && gallery.isLoading && gallery.items.length > 0 && (<Flex align="center" justify="center" py="2">diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsxindex 011025c20d..31c52a5f50 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.browser.test.tsx@@ -50,6 +50,19 @@ const renderViewTabs = async (): Promise<{);});+ // Match the release accessibility journey: wait until Ark has measured the+ // moving indicator and removed its initial checked-item fallback styling.+ await act(+ () =>+ new Promise<void>((resolve) => {+ requestAnimationFrame(() =>+ requestAnimationFrame(() => {+ setTimeout(resolve, 200);+ })+ );+ })+ );+const items = [...host.querySelectorAll<HTMLElement>('[data-part="item"]')];return {@@ -69,15 +82,19 @@ describe('GalleryViewTabs', () => {expect(counts.map((count) => count.textContent)).toEqual(['148', '7']);});- it('keeps the count readable on the selected segment', async () => {- const { counts, indicator, items } = await renderViewTabs();+ it('keeps the count readable against the selected segment itself', async () => {+ const { counts, items } = await renderViewTabs();const checkedIndex = items.findIndex((item) => item.dataset.state === 'checked');const count = counts[checkedIndex]!;const style = getComputedStyle(count);- // The selected segment is filled with `accent.solid`, so a count pinned to- // `fg.muted` (rather than dimmed from the item's own colour) is unreadable.- const ratio = getContrastRatio(style.color, getComputedStyle(indicator).backgroundColor, Number(style.opacity));+ // Axe evaluates the selected item's own background rather than a moving+ // indicator sibling behind it, so that local surface must carry the fill.+ const ratio = getContrastRatio(+ style.color,+ getComputedStyle(items[checkedIndex]!).backgroundColor,+ Number(style.opacity)+ );expect(ratio).toBeGreaterThanOrEqual(4.5);});diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.tsxindex 371fad7cd2..5c20339fa2 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryViewTabs.tsx@@ -11,6 +11,7 @@ const GALLERY_VIEW_TABS = [{ labelKey: 'common.media', value: 'images' },{ labelKey: 'common.assets', value: 'assets' },] satisfies { labelKey: string; value: GalleryView }[];+const CHECKED_VIEW_TAB_STYLES = { bg: 'accent.solid', color: 'accent.contrast' } as const;/*** Media / Assets, each carrying the selected board's count for that view so@@ -48,7 +49,7 @@ export const GalleryViewTabs = () => {const count = selectedBoard ? getGalleryCountForView(selectedBoard, value) : null;return (- <SegmentGroup.Item key={value} value={value}>+ <SegmentGroup.Item key={value} value={value} _checked={CHECKED_VIEW_TAB_STYLES}><SegmentGroup.ItemHiddenInput /><SegmentGroup.ItemText display="flex" fontSize="xs" gap="1.5">{t(labelKey)}