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(ui): complete preset accessibility
joshistoast47bc60769f97
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 917dcf360f..2204c65c98 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -4,6 +4,7 @@"buttonLabel": "Command palette","buttonTooltip": "Command palette ({{hotkey}})","inputLabel": "Search commands and settings",+ "layoutPresetCommand": "{{name}} layout","resultsLabel": "Command palette results","placeholders": {"root": "Search commands, settings, and more…",@@ -354,6 +355,7 @@"name": "Preset name","none": "No custom presets yet. Arrange the dock, then choose Save as new preset.","noInvocationSource": "This layout does not contain an invocation source.",+ "reorderInstructions": "To reorder a layout preset, press Space. Use the Left and Right arrow keys to move it, then press Space to drop or Escape to cancel.","reorderNamed": "Reorder {{name}}","restore": "Restore shipped preset defaults","restoreNamed": "Restore {{name}} defaults",diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.test.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.test.tsindex e060fd47dc..e2f59143ad 100644--- a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.test.ts+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.test.ts@@ -1,3 +1,4 @@+import { getLayoutPresetCommandTitleOverrides } from '@workbench/layoutPresetSnapshots';import { createInitialWorkbenchState } from '@workbench/workbenchState';import { describe, expect, it } from 'vitest';@@ -6,7 +7,6 @@ import {FIRST_PARTY_APP_COMMAND_IDS,FIRST_PARTY_COMMAND_IDS,FIRST_PARTY_IMAGE_RECALL_COMMAND_IDS,- getLayoutPresetCommands,} from './firstPartyCommands';const centrallyOwnedCommandIds = new Set(FIRST_PARTY_COMMAND_IDS);@@ -19,11 +19,9 @@ describe('first-party hotkey commands', () => {layoutPresetMetadataOverrides: { compose: { label: 'Writing' } },};- expect(getLayoutPresetCommands(account).map(({ title }) => title)).toEqual([- 'Writing layout',- 'Edit layout',- 'Automate layout',- ]);+ expect(getLayoutPresetCommandTitleOverrides(account, (name) => `${name} layout`)).toEqual({+ 'app.selectComposePreset': 'Writing layout',+ });});it('registers handlers for implemented app and shared image recall commands', () => {diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.tsindex 7ba84319af..c3eb62025f 100644--- a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts@@ -1,6 +1,5 @@import type { ImageRecallKind } from '@workbench/image-actions/imageRecall';import type { ResultDestination } from '@workbench/invocationContracts';-import type { AccountState } from '@workbench/projectContracts';import { invalidateGallery } from '@features/gallery/queries';import {@@ -21,38 +20,20 @@ import {import { useQueryClient } from '@tanstack/react-query';import { submitActiveInvocation } from '@workbench/activeInvocationSubmission';import { builtInLayoutPresetDescriptors } from '@workbench/layoutPresets';-import { resolveSavedLayoutPreset } from '@workbench/layoutPresetSnapshots';import { toggleCommandPalette } from '@workbench/palette/paletteStore';import { getWorkbenchPreferences } from '@workbench/settings/store';import { openProjectSwitcher } from '@workbench/shell/topbar/projectSwitcherStore';import { openWidgetPlacement } from '@workbench/widgetPlacementCommands';import { getWidgetsForRegion } from '@workbench/widgetRegistry';import { getProjectWidgetValues } from '@workbench/widgetState';-import {- useWorkbenchCommands,- useWorkbenchExtensions,- useWorkbenchQueries,- useWorkbenchSelector,-} from '@workbench/WorkbenchContext';-import { useEffect, useEffectEvent } from 'react';+import { useWorkbenchCommands, useWorkbenchExtensions, useWorkbenchQueries } from '@workbench/WorkbenchContext';-/** ⌥1 / ⌥2 / ⌥3 — the three shipped layout presets, in strip order. */const layoutPresetCommands = builtInLayoutPresetDescriptors.map(({ hotkeyId, preset }) => ({id: `app.${hotkeyId}`,presetId: preset.id,+ title: `${preset.label} layout`,}));-export const getLayoutPresetCommands = (account: AccountState) =>- layoutPresetCommands.map((command) => ({- ...command,- title: `${resolveSavedLayoutPreset(account, command.presetId).label} layout`,- }));--const areLayoutPresetCommandsEqual = (- left: ReturnType<typeof getLayoutPresetCommands>,- right: ReturnType<typeof getLayoutPresetCommands>-): boolean => left.length === right.length && left.every((command, index) => command.title === right[index]?.title);-const imageRecallCommands: Record<string, ImageRecallKind> = {'gallery.remix': 'remix','viewer.recallAll': 'all',@@ -103,10 +84,6 @@ export const useRegisterFirstPartyCommands = () => {const queries = useWorkbenchQueries();const queryClient = useQueryClient();const { layout, notifications, queue, widgets } = commands;- const currentLayoutPresetCommands = useWorkbenchSelector(- (snapshot) => getLayoutPresetCommands(snapshot.account),- areLayoutPresetCommandsEqual- );useInvocationTemplatesSelector((snapshot) => snapshot.status);useMountEffect(() => {@@ -118,11 +95,11 @@ export const useRegisterFirstPartyCommands = () => {* is never written back to the project — "just this once, send it to the* gallery" must not silently retarget every subsequent invoke.*/- const submitInvocation = useEffectEvent(async (destinationOverride?: ResultDestination) => {+ const submitInvocation = async (destinationOverride?: ResultDestination) => {await submitActiveInvocation({ commands, destinationOverride, getModels: getAvailableModels, queries });- });+ };- const recallSelectedImage = useEffectEvent(async (kind: ImageRecallKind) => {+ const recallSelectedImage = async (kind: ImageRecallKind) => {const owner = captureAccountScope();try {@@ -170,7 +147,7 @@ export const useRegisterFirstPartyCommands = () => {throw error;}- });+ };useMountEffect(() =>commandApi.register({@@ -180,7 +157,7 @@ export const useRegisterFirstPartyCommands = () => {}));- useEffect(() => {+ useMountEffect(() => {const disposers = [commandApi.register({ handler: () => submitInvocation(), id: 'app.invoke', title: 'Invoke' }),commandApi.register({ handler: () => submitInvocation(), id: 'app.invokeFront', title: 'Invoke front' }),@@ -203,7 +180,7 @@ export const useRegisterFirstPartyCommands = () => {id: 'app.saveLayoutPreset',title: 'Save changes to the active layout preset',}),- ...currentLayoutPresetCommands.map(({ id, presetId, title }) =>+ ...layoutPresetCommands.map(({ id, presetId, title }) =>commandApi.register({ handler: () => void layout.activatePreset(presetId), id, title })),commandApi.register({@@ -376,5 +353,5 @@ export const useRegisterFirstPartyCommands = () => {return () => {disposers.forEach((dispose) => dispose());};- }, [commandApi, commands, currentLayoutPresetCommands, layout, notifications, queries, queryClient, queue, widgets]);+ });};diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.ts b/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.tsindex cac1777df2..8334ffa8d6 100644--- a/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.ts+++ b/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.ts@@ -9,7 +9,25 @@ import type {import type { AccountState, Project } from '@workbench/projectContracts';import type { WidgetInstanceId } from '@workbench/widgetContracts';-import { getLayoutPreset, isBuiltInLayoutPresetId, resolveLayoutPresetId } from '@workbench/layoutPresets';+import {+ builtInLayoutPresetDescriptors,+ getLayoutPreset,+ isBuiltInLayoutPresetId,+ resolveLayoutPresetId,+} from '@workbench/layoutPresets';++/** Palette labels follow account-owned preset names without making command registration reactive. */+export const getLayoutPresetCommandTitleOverrides = (+ account: AccountState,+ formatTitle: (presetName: string) => string+): Readonly<Record<string, string>> =>+ Object.fromEntries(+ builtInLayoutPresetDescriptors.flatMap(({ hotkeyId, preset }) => {+ const savedLabel = resolveSavedLayoutPreset(account, preset.id).label;++ return savedLabel === preset.label ? [] : [[`app.${hotkeyId}`, formatTitle(savedLabel)]];+ })+ );const widgetRegions: WidgetRegion[] = ['left', 'right', 'bottom', 'center'];diff --git a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsx b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsxindex b251a3cc2e..d1a9f8ec6c 100644--- a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsx@@ -9,6 +9,7 @@ import { getModelsSnapshot } from '@features/models';import { getQueueQueryScope, getQueueReadModelOptions } from '@features/queue/queries';import { queryClient } from '@platform/query/client';import { recallProjectPromptHistoryItem, selectProjectGenerateModel } from '@workbench/generationSettingsOrchestration';+import { getLayoutPresetCommandTitleOverrides } from '@workbench/layoutPresetSnapshots';import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';import { useNotify } from '@workbench/useNotify';import { getProjectWidgetValues } from '@workbench/widgetState';@@ -17,6 +18,7 @@ import {useWorkbenchCommands,useWorkbenchExtensions,useWorkbenchQueries,+ useWorkbenchSelector,} from '@workbench/WorkbenchContext';import { useCallback, useMemo, useSyncExternalStore } from 'react';import { useTranslation } from 'react-i18next';@@ -75,12 +77,17 @@ const WorkbenchCommandPaletteDialog = ({const notify = useNotify();const workbenchQueries = useWorkbenchQueries();const projectId = useActiveProjectSelector((project) => project.id);+ const account = useWorkbenchSelector((snapshot) => snapshot.account);const promptHistory = useActiveProjectSelector((project) => project.promptHistory);const presentWidgetTypeIds = useActiveProjectSelector((project) =>[...new Set(Object.values(project.widgetInstances).map((instance) => instance.typeId))].sort());const paletteStore = extensions.stores.palette;const paletteContributions = useSyncExternalStore(paletteStore.subscribe, paletteStore.list, paletteStore.list);+ const commandTitleOverrides = useMemo(+ () => getLayoutPresetCommandTitleOverrides(account, (name) => t('commandPalette.layoutPresetCommand', { name })),+ [account, t]+ );const executeCommand = useCallback((commandId: string) => {@@ -102,6 +109,7 @@ const WorkbenchCommandPaletteDialog = ({formatHotkey,presentWidgetTypeIds: new Set(presentWidgetTypeIds),t,+ titleOverrides: commandTitleOverrides,}),...paletteContributions.map((contribution) =>buildExtensionPaletteEntry(contribution, extensions.commands.executeForSource)@@ -111,6 +119,7 @@ const WorkbenchCommandPaletteDialog = ({],[catalog,+ commandTitleOverrides,executeCommand,extensions,formatHotkey,diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.test.tsindex a043306703..ebe5c2ecd7 100644--- a/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts@@ -2,7 +2,9 @@ import type { TFunction } from 'i18next';import { firstPartyHotkeyCatalog } from '@workbench/hotkeys/catalog';import { formatHotkeyForPlatform } from '@workbench/hotkeys/keys';+import { getLayoutPresetCommandTitleOverrides } from '@workbench/layoutPresetSnapshots';import { DEFAULT_PREFERENCES } from '@workbench/settings/store';+import { createInitialWorkbenchState } from '@workbench/workbenchState';import { describe, expect, it, vi } from 'vitest';import type { PaletteEntry } from './entries';@@ -90,6 +92,27 @@ describe('buildCatalogCommandEntries', () => {expect(generateTab).toMatchObject({ group: 'Navigation', showInEmptyState: true, title: 'Go to Generate' });});+ it('uses account-renamed layout preset titles in palette rows', () => {+ const initial = createInitialWorkbenchState();+ const account = {+ ...initial.account,+ layoutPresetMetadataOverrides: { compose: { label: 'Writing' } },+ };+ const entries = buildCatalogCommandEntries({+ catalog: firstPartyHotkeyCatalog,+ customHotkeys: {},+ execute: noop,+ formatHotkey: formatHotkeyForPlatform,+ presentWidgetTypeIds: new Set(),+ t,+ titleOverrides: getLayoutPresetCommandTitleOverrides(account, (name) =>+ t('commandPalette.layoutPresetCommand', { defaultValue: '{{name}} layout', name })+ ),+ });++ expect(entries.find((entry) => entry.id === 'app.selectComposePreset')?.title).toBe('Writing layout');+ });+it('hides unimplemented and hotkey-only commands', () => {const ids = build(new Set(['canvas', 'gallery', 'preview', 'workflow'])).map((entry) => entry.id);diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.tsindex 2534782779..75c9cf6ae5 100644--- a/invokeai/frontend/webv2/src/workbench/palette/entries.ts+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.ts@@ -229,6 +229,7 @@ export const buildCatalogCommandEntries = ({formatHotkey,presentWidgetTypeIds,t,+ titleOverrides,}: {catalog: readonly HotkeyDefinition[];customHotkeys: CustomHotkeys;@@ -236,6 +237,7 @@ export const buildCatalogCommandEntries = ({formatHotkey: (key: string) => string[];presentWidgetTypeIds: ReadonlySet<string>;t: TFunction;+ titleOverrides?: Readonly<Record<string, string>>;}): PaletteEntry[] =>catalog.filter((definition) => definition.implemented !== false && !PALETTE_HIDDEN_COMMANDS.has(definition.commandId))@@ -261,9 +263,11 @@ export const buildCatalogCommandEntries = ({keywords: widgetGroup?.group,run: () => execute(definition.commandId),showInEmptyState: rawGroup === 'Navigation',- title: t(`commandPalette.commands.${definition.commandId.replace('.', '_')}`, {- defaultValue: TITLE_OVERRIDES[definition.commandId] ?? definition.title,- }),+ title:+ titleOverrides?.[definition.commandId] ??+ t(`commandPalette.commands.${definition.commandId.replace('.', '_')}`, {+ defaultValue: TITLE_OVERRIDES[definition.commandId] ?? definition.title,+ }),};});diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.browser.test.tsxindex 9f3192c573..bce4886386 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.browser.test.tsx@@ -118,4 +118,41 @@ describe('LayoutPresetDialog', () => {);expect(onClose).toHaveBeenCalledOnce();});++ it('makes the fallback icon selected and keyboard-focusable for a retired icon id', async () => {+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);++ await act(async () => {+ root?.render(+ <ChakraProvider value={system}>+ <LayoutPresetDialog+ defaultRoute={BUILT_IN_DEFAULT_ROUTE}+ iconId="retired-icon"+ isOpen+ name="Legacy preset"+ sourceOptions={BUILT_IN_SOURCE_OPTIONS}+ submitLabel="Save preset"+ title="Edit layout preset"+ onClose={vi.fn()}+ onSubmit={vi.fn()}+ />+ </ChakraProvider>+ );+ await new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 50);+ });+ });++ const fallback = document.querySelector<HTMLButtonElement>('[role="radio"][data-icon-id="layout-grid"]');+ expect(fallback).toHaveAttribute('aria-checked', 'true');+ expect(fallback?.tabIndex).toBe(0);+ fallback?.focus();+ await act(() => userEvent.keyboard('{ArrowRight}'));++ const next = document.querySelector<HTMLButtonElement>('[role="radio"][data-icon-id="layout-dashboard"]');+ expect(next).toHaveAttribute('aria-checked', 'true');+ expect(next).toHaveFocus();+ });});diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.browser.test.tsxindex 64e6c9227e..394ff37305 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.browser.test.tsx@@ -15,6 +15,8 @@ vi.mock('react-i18next', () => ({t: (key: string) =>({'topbar.presets.layoutPreset': 'Layout preset',+ 'topbar.presets.reorderInstructions':+ 'To reorder a layout preset, press Space. Use the Left and Right arrow keys to move it, then press Space to drop or Escape to cancel.','topbar.presets.saveAsTooltip': 'Save this layout as a new preset','topbar.presets.unsaved': 'Unsaved changes',})[key] ?? key,@@ -86,19 +88,26 @@ const mouse = (type: string, target: EventTarget, clientX: number, clientY: numb);};-const touch = (type: string, target: EventTarget, touchTarget: EventTarget, clientX: number, clientY: number): void => {+const touch = (+ type: string,+ target: EventTarget,+ touchTarget: EventTarget,+ clientX: number,+ clientY: number+): TouchEvent => {const point = new Touch({ clientX, clientY, identifier: 1, target: touchTarget });const isEnd = type === 'touchend' || type === 'touchcancel';+ const event = new TouchEvent(type, {+ bubbles: true,+ cancelable: true,+ changedTouches: [point],+ targetTouches: isEnd ? [] : [point],+ touches: isEnd ? [] : [point],+ });- target.dispatchEvent(- new TouchEvent(type, {- bubbles: true,- cancelable: true,- changedTouches: [point],- targetTouches: isEnd ? [] : [point],- touches: isEnd ? [] : [point],- })- );+ target.dispatchEvent(event);++ return event;};beforeEach(() => {@@ -151,6 +160,39 @@ describe('LayoutPresetStrip', () => {expect(store.getSnapshot().activeProject.layout.presetId).toBe(activeBeforeDrag);});+ it('supports keyboard reordering with sortable drag semantics', async () => {+ store.commands.layout.applyPreset('compose');+ await renderStrip();+ const source = presetTab('compose');+ expect(source).not.toBeNull();+ expect(source).toHaveAttribute('aria-roledescription', 'sortable');+ const instructions = document.getElementById(source!.getAttribute('aria-describedby') ?? '');+ expect(instructions?.textContent).toContain('press Space');+ expect(instructions?.textContent).not.toContain('Enter');+ expect(+ Array.from(document.querySelectorAll<HTMLElement>('[role="tab"]')).filter((tab) => tab.tabIndex === 0)+ ).toEqual([source]);+ source!.focus();++ await act(() => userEvent.keyboard('{Space}'));+ await act(() => userEvent.keyboard('{End}'));+ await act(() => userEvent.keyboard('{ArrowDown}'));+ expect(document.querySelector('[role="menu"]')).toBeNull();+ await act(() => userEvent.keyboard('{ArrowRight}'));+ await act(() => userEvent.keyboard('{Space}'));++ expect(store.getSnapshot().account.layoutPresetOrder).toEqual(['custom-1', 'compose', 'edit', 'automate']);+ expect(store.getSnapshot().activeProject.layout.presetId).toBe('compose');+ expect(store.getSnapshot().account.activeLayoutPresetId).toBe('compose');++ const movedSource = presetTab('compose');+ movedSource?.focus();+ await act(() => userEvent.keyboard('{Space}'));+ expect(movedSource?.style.opacity).toBe('0.5');+ await act(() => userEvent.keyboard('{Tab}'));+ expect(movedSource?.style.opacity).not.toBe('0.5');+ });+it('keeps a non-overflowing strip stationary while dragging near its right edge', async () => {await renderStrip();const scrollContainer = document.querySelector<HTMLElement>('[data-layout-preset-scroll]');@@ -258,4 +300,30 @@ describe('LayoutPresetStrip', () => {expect(source!.style.opacity).not.toBe('0.5');expect(store.getSnapshot().account.layoutPresetOrder).toEqual(['custom-1', 'edit', 'automate', 'compose']);});++ it('leaves a short horizontal touch gesture to an overflowing scroll strip', async () => {+ for (let index = 2; index <= 8; index += 1) {+ store.commands.layout.createPreset(`custom-${index}`, `Custom ${index}`, 'star');+ }+ await renderStrip();+ const scrollContainer = document.querySelector<HTMLElement>('[data-layout-preset-scroll]');+ const source = presetTab('compose');+ expect(scrollContainer).not.toBeNull();+ expect(source).not.toBeNull();+ expect(scrollContainer!.scrollWidth).toBeGreaterThan(scrollContainer!.clientWidth);+ const orderBeforePan = store.getSnapshot().account.layoutPresetOrder;+ const start = source!.getBoundingClientRect();+ const startX = start.left + start.width / 2;+ const startY = start.top + start.height / 2;++ await act(() => touch('touchstart', source!, source!, startX, startY));+ const move = touch('touchmove', source!, source!, startX - 40, startY);+ scrollContainer!.scrollLeft = 40;+ await act(() => touch('touchend', source!, source!, startX - 40, startY));++ expect(move.defaultPrevented).toBe(false);+ expect(scrollContainer!.scrollLeft).toBe(40);+ expect(source!.style.opacity).not.toBe('0.5');+ expect(store.getSnapshot().account.layoutPresetOrder).toBe(orderBeforePan);+ });});diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsxindex 6e627d60af..9ced5985d4 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx@@ -4,9 +4,22 @@ import type { Project } from '@workbench/projectContracts';import type { KeyboardEvent, MouseEvent } from 'react';import { Box, HStack, Icon, Menu, Portal, Text, VisuallyHidden } from '@chakra-ui/react';-import { closestCenter, DndContext, MouseSensor, TouchSensor, useSensor, useSensors } from '@dnd-kit/core';+import {+ closestCenter,+ DndContext,+ KeyboardSensor,+ MouseSensor,+ TouchSensor,+ useSensor,+ useSensors,+} from '@dnd-kit/core';import { restrictToHorizontalAxis, restrictToParentElement } from '@dnd-kit/modifiers';-import { horizontalListSortingStrategy, SortableContext, useSortable } from '@dnd-kit/sortable';+import {+ horizontalListSortingStrategy,+ sortableKeyboardCoordinates,+ SortableContext,+ useSortable,+} from '@dnd-kit/sortable';import { CSS } from '@dnd-kit/utilities';import { IconButton } from '@platform/ui/Button';import { MenuContent } from '@platform/ui/Menu';@@ -40,7 +53,12 @@ import { useTopbarShortcut } from './useTopbarShortcut';const PRESET_MENU_ATTRIBUTE = 'data-preset-menu';const PRESET_SCROLL_CSS = { '&::-webkit-scrollbar': { display: 'none' }, scrollbarWidth: 'none' } as const;+const PRESET_TAB_KEYS_BLOCKED_DURING_DRAG = new Set(['ArrowDown', 'ArrowLeft', 'ArrowRight', 'End', 'Home']);const DND_MODIFIERS = [restrictToHorizontalAxis, restrictToParentElement];+const KEYBOARD_SENSOR_OPTIONS = {+ coordinateGetter: sortableKeyboardCoordinates,+ keyboardCodes: { cancel: ['Escape'], end: ['Space', 'Tab'], start: ['Space'] },+};const MOUSE_SENSOR_OPTIONS = { activationConstraint: { distance: 6 } } as const;const TOUCH_SENSOR_OPTIONS = { activationConstraint: { delay: 250, tolerance: 5 } } as const;@@ -66,9 +84,14 @@ export const LayoutPresetStrip = () => {const sourceOptions = useActiveProjectSelector(selectPlacedGraphWidgetSources);const presets = useMemo(() => getOrderedLayoutPresets(account), [account]);const presetIds = useMemo(() => presets.map(({ id }) => id), [presets]);+ const dndAccessibility = useMemo(+ () => ({ screenReaderInstructions: { draggable: t('topbar.presets.reorderInstructions') } }),+ [t]+ );const sensors = useSensors(useSensor(MouseSensor, MOUSE_SENSOR_OPTIONS),- useSensor(TouchSensor, TOUCH_SENSOR_OPTIONS)+ useSensor(TouchSensor, TOUCH_SENSOR_OPTIONS),+ useSensor(KeyboardSensor, KEYBOARD_SENSOR_OPTIONS));const autoScroll = useMemo<AutoScrollOptions>(() => ({@@ -131,6 +154,7 @@ export const LayoutPresetStrip = () => {overflowX="auto"><DndContext+ accessibility={dndAccessibility}autoScroll={autoScroll}collisionDetection={closestCenter}modifiers={DND_MODIFIERS}@@ -223,7 +247,10 @@ const PresetTab = ({}) => {const { t } = useTranslation();const icon = resolveLayoutPresetIcon(preset.iconId);- const { isDragging, listeners, setNodeRef, transform, transition } = useSortable({ id: preset.id });+ const { attributes, isDragging, listeners, setNodeRef, transform, transition } = useSortable({+ attributes: { role: 'tab', roleDescription: 'sortable', tabIndex: isActive ? 0 : -1 },+ id: preset.id,+ });const dndStyle = useMemo(() => ({opacity: isDragging ? 0.5 : undefined,@@ -267,6 +294,16 @@ const PresetTab = ({const handleKeyDown = useCallback((event: KeyboardEvent<HTMLButtonElement>) => {+ if (isDragging && PRESET_TAB_KEYS_BLOCKED_DURING_DRAG.has(event.key)) {+ event.preventDefault();+ }++ listeners?.onKeyDown?.(event);++ if (event.defaultPrevented) {+ return;+ }+if (!isActive || event.key !== 'ArrowDown') {return;}@@ -274,12 +311,13 @@ const PresetTab = ({event.preventDefault();onOpenMenu({ anchor: event.currentTarget.getBoundingClientRect(), preset });},- [isActive, onOpenMenu, preset]+ [isActive, isDragging, listeners, onOpenMenu, preset]);return (<Tabs.Triggerref={setNodeRef}+ {...attributes}{...listeners}aria-label={showDrift ? `${preset.label}, ${t('topbar.presets.unsaved')}` : preset.label}aria-keyshortcuts={isActive ? 'ArrowDown' : undefined}diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsxindex 3a05ad11e1..49472a4b45 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsx@@ -19,11 +19,6 @@ import { RoutingDestinationSegments } from './RoutingDestinationSegments';const MENU_POSITIONING = { placement: 'bottom-end' } as const;-const destinationWidgetTypeIds: Record<ResultDestination, 'canvas' | 'gallery'> = {- canvas: 'canvas',- gallery: 'gallery',-};-export const RoutingControl = ({ state }: { state: InvocationState }) => {const { t } = useTranslation();const { generation } = useWorkbenchCommands();@@ -33,7 +28,6 @@ export const RoutingControl = ({ state }: { state: InvocationState }) => {const isLocked = invocation.sourceLocked || invocation.destinationLocked;const hasSource = placedTypeIds.has(getWidgetTypeIdForSourceId(invocation.sourceId));const sourceTypeId = getWidgetTypeIdForSourceId(invocation.sourceId);- const destinationTypeId = destinationWidgetTypeIds[invocation.destination];const accessibleName = describeRoute({destination: invocation.destination,destinationLocked: invocation.destinationLocked,@@ -47,7 +41,7 @@ export const RoutingControl = ({ state }: { state: InvocationState }) => {boxSize: '3.5',color: 'fg.muted',[`data-routing-${type}-icon`]: '',- icon: getWidgetById(type === 'source' ? sourceTypeId : destinationTypeId)?.manifest.icon,+ icon: getWidgetById(type === 'source' ? sourceTypeId : invocation.destination)?.manifest.icon,position: 'absolute',top: type === 'source' ? '4px' : undefined,left: type === 'source' ? '4px' : undefined,diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingDestinationSegments.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingDestinationSegments.tsxindex 4329408b35..06a4ddd1a7 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingDestinationSegments.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingDestinationSegments.tsx@@ -6,11 +6,6 @@ import { getDestinationLabel, resultDestinations } from '@workbench/invocation';import { getWidgetById } from '@workbench/widgetRegistry';import { useCallback } from 'react';-const destinationWidgetTypeIds: Record<ResultDestination, 'canvas' | 'gallery'> = {- canvas: 'canvas',- gallery: 'gallery',-};-export const RoutingDestinationSegments = ({ariaLabel,disabled,@@ -38,7 +33,7 @@ export const RoutingDestinationSegments = ({<SegmentGroup.Item key={destination.id} flex="1" justifyContent="center" value={destination.id}><SegmentGroup.ItemHiddenInput /><SegmentGroup.ItemText display="flex" alignItems="center" gap="1.5">- <WidgetIcon boxSize="3.5" icon={getWidgetById(destinationWidgetTypeIds[destination.id])?.manifest.icon} />+ <WidgetIcon boxSize="3.5" icon={getWidgetById(destination.id)?.manifest.icon} />{getDestinationLabel(destination.id)}</SegmentGroup.ItemText></SegmentGroup.Item>