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.

fix(webv2): give the preview header toggles one on-state and tooltips

joshistoast245f70895704
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.browser.test.tsx
new file mode 100644
index 0000000000..62f6fe1e46
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.browser.test.tsx
@@ -0,0 +1,172 @@
+import type { WidgetViewProps } from '@workbench/widgetContracts';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { createInstance } from 'i18next';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { I18nextProvider, initReactI18next } from 'react-i18next';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { userEvent } from 'vitest/browser';
+
+import { PreviewHeaderActions } from './PreviewHeaderActions';
+
+const i18n = createInstance();
+void i18n.use(initReactI18next).init({
+ fallbackLng: 'en',
+ initAsync: false,
+ lng: 'en',
+ resources: {
+ en: {
+ translation: {
+ widgets: {
+ preview: {
+ hideFilmstrip: 'Hide filmstrip',
+ hideInProgressDiffusion: 'Hide in-progress diffusion',
+ showFilmstrip: 'Show filmstrip',
+ showInProgressDiffusion: 'Show in-progress diffusion',
+ },
+ },
+ },
+ },
+ },
+});
+
+const state = vi.hoisted(() => ({ filmstripVisible: true, showProgressImagesInViewer: true }));
+const patchValues = vi.hoisted(() => vi.fn());
+const updateProjectPreferences = vi.hoisted(() => vi.fn());
+
+vi.mock('@features/queue/react', () => ({ useProgressImage: () => null }));
+
+// No selection published, so the action strip stays out and the two toggles are
+// the only buttons in the header.
+vi.mock('./previewHeaderStore', () => ({
+ usePreviewHeaderContext: () => ({
+ actionItem: null,
+ actions: null,
+ copyCurrentVideoFrame: null,
+ isVideoFrameCopyAvailable: false,
+ openItemMenu: vi.fn(),
+ openVideoDetails: null,
+ }),
+}));
+
+vi.mock('@workbench/widgetState', () => ({
+ getProjectWidgetValues: () => ({ filmstripVisible: state.filmstripVisible }),
+}));
+
+vi.mock('@workbench/WorkbenchContext', () => ({
+ useActiveProjectSelector: (select: (project: unknown) => unknown) =>
+ select({ settings: { showProgressImagesInViewer: state.showProgressImagesInViewer } }),
+ useWorkbenchCommands: () => ({
+ account: { updateProjectPreferences },
+ widgets: { patchValues },
+ }),
+}));
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const settle = (action: () => void): Promise<void> =>
+ act(async () => {
+ action();
+ await new Promise<void>((resolve) => {
+ globalThis.setTimeout(resolve, 40);
+ });
+ });
+
+const render = async () => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+
+ await settle(() => {
+ root?.render(
+ <I18nextProvider i18n={i18n}>
+ <ChakraProvider value={system}>
+ <PreviewHeaderActions {...({ region: 'center' } as unknown as WidgetViewProps)} />
+ </ChakraProvider>
+ </I18nextProvider>
+ );
+ });
+};
+
+const button = (label: string): HTMLButtonElement =>
+ host!.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`)!;
+
+beforeEach(() => {
+ state.filmstripVisible = true;
+ state.showProgressImagesInViewer = true;
+ patchValues.mockClear();
+ updateProjectPreferences.mockClear();
+});
+
+afterEach(async () => {
+ await settle(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('preview header toggles', () => {
+ it('states both on/off positions the same way', async () => {
+ // The filmstrip toggle used to signal "on" with an `fg.muted` → `fg` shift
+ // on a permanently ghost button, while the in-progress toggle next to it
+ // filled. One control type, one vocabulary.
+ await render();
+ const bothOn = [button('Hide filmstrip'), button('Hide in-progress diffusion')];
+
+ for (const control of bothOn) {
+ expect(control.getAttribute('aria-pressed'), control.ariaLabel ?? '').toBe('true');
+ }
+
+ const [filmstripOn, progressOn] = bothOn.map((control) => getComputedStyle(control).backgroundColor);
+ expect(filmstripOn).toBe(progressOn);
+
+ state.filmstripVisible = false;
+ state.showProgressImagesInViewer = false;
+ await render();
+ const bothOff = [button('Show filmstrip'), button('Show in-progress diffusion')];
+
+ for (const control of bothOff) {
+ expect(control.getAttribute('aria-pressed'), control.ariaLabel ?? '').toBe('false');
+ }
+
+ const [filmstripOff, progressOff] = bothOff.map((control) => getComputedStyle(control).backgroundColor);
+ expect(filmstripOff).toBe(progressOff);
+ expect(filmstripOff).not.toBe(filmstripOn);
+ });
+
+ it('gives both a hover tooltip rather than the native title attribute', async () => {
+ // They previously relied on `title`, which is delayed, unstyled, and unlike
+ // every other button in the same header row.
+ await render();
+
+ for (const label of ['Hide filmstrip', 'Hide in-progress diffusion']) {
+ const control = button(label);
+ expect(control.hasAttribute('title'), label).toBe(false);
+
+ await act(async () => {
+ await userEvent.hover(control);
+ });
+ await vi.waitFor(() =>
+ expect(document.querySelector('[data-scope="tooltip"][data-part="content"]')?.textContent, label).toBe(label)
+ );
+
+ await act(async () => {
+ await userEvent.unhover(control);
+ });
+ }
+ });
+
+ it('still toggles the setting each one owns', async () => {
+ await render();
+
+ await settle(() => button('Hide filmstrip').click());
+ expect(patchValues).toHaveBeenCalledWith('preview', { filmstripVisible: false });
+
+ await settle(() => button('Hide in-progress diffusion').click());
+ expect(updateProjectPreferences).toHaveBeenCalledWith({ showProgressImagesInViewer: false });
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx
index 6b7c4df311..46ce2f5c25 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx
@@ -1,8 +1,8 @@
import type { WidgetViewProps } from '@workbench/widgetContracts';
-import { Box, HStack, Icon } from '@chakra-ui/react';
+import { Box, HStack } from '@chakra-ui/react';
import { useProgressImage } from '@features/queue/react';
-import { IconButton } from '@platform/ui';
+import { ToggleIconButton } from '@platform/ui';
import { getProjectWidgetValues } from '@workbench/widgetState';
import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
import { GalleryThumbnailsIcon, HourglassIcon } from 'lucide-react';
@@ -58,27 +58,24 @@ export const PreviewHeaderActions = ({ region }: WidgetViewProps) => {
<Box bg="border.subtle" flexShrink={0} h="4" w="1px" />
</>
) : null}
- <IconButton
- aria-label={filmstripLabel}
- color={isFilmstripVisible ? 'fg' : 'fg.muted'}
- size="2xs"
- title={filmstripLabel}
- variant="ghost"
- onClick={toggleFilmstrip}
- >
- <Icon as={GalleryThumbnailsIcon} boxSize="3.5" />
- </IconButton>
- <IconButton
- aria-label={label}
- colorPalette={showProgressImagesInViewer ? 'accent' : 'gray'}
+ {/* Both toggles go through `ToggleIconButton` so they read as one control
+ type: the filled variant carries "on", `aria-pressed` carries it for
+ assistive tech, and the label doubles as the tooltip. */}
+ <ToggleIconButton
+ checked={isFilmstripVisible}
+ icon={GalleryThumbnailsIcon}
+ label={filmstripLabel}
+ onCheckedChange={toggleFilmstrip}
+ />
+ <ToggleIconButton
+ checked={showProgressImagesInViewer}
+ icon={HourglassIcon}
+ label={label}
+ // Dimmed while there is nothing in flight to show. Spread after the
+ // primitive's own props, so it survives.
opacity={hasProgressImage || showProgressImagesInViewer ? 1 : 0.7}
- size="2xs"
- title={label}
- variant={showProgressImagesInViewer ? 'solid' : 'ghost'}
- onClick={toggleProgressImages}
- >
- <Icon as={HourglassIcon} boxSize="3.5" />
- </IconButton>
+ onCheckedChange={toggleProgressImages}
+ />
</HStack>
);
};