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): keep the field's error in the seed input's description beside the preview
Josh Corbett0b6e4e2484be
diff --git a/invokeai/frontend/webv2/src/platform/ui/SeedInput.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/SeedInput.browser.test.tsxindex 945b158f14..1fb718acd8 100644--- a/invokeai/frontend/webv2/src/platform/ui/SeedInput.browser.test.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/SeedInput.browser.test.tsx@@ -9,6 +9,7 @@ import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { userEvent } from 'vitest/browser';+import { Field } from './Field';import { SeedInput, type SeedInputPatch } from './SeedInput';(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;@@ -195,6 +196,44 @@ describe('SeedInput', () => {expect(seedInput()?.getAttribute('aria-describedby')).toBeNull();});+ it("keeps the field's error in the input's description alongside the preview", async () => {+ await act(() => {+ root.render(+ <ChakraProvider value={system}>+ <Field error="Out of range" label="Seed">+ <Host initialSeed={42} seedMode="increment" onCommit={vi.fn()} />+ </Field>+ </ChakraProvider>+ );+ });++ const errorId = host.querySelector('[data-part="error-text"]')?.id;+ const previewId = host.querySelector('[data-testid="seed-sequence-preview"]')?.id;+ const describedBy = seedInput()?.getAttribute('aria-describedby')?.split(' ') ?? [];++ expect(errorId).toBeTruthy();+ expect(describedBy).toContain(errorId);+ expect(describedBy).toContain(previewId);+ });++ it("keeps the field's error as the whole description while the seed holds", async () => {+ await act(() => {+ root.render(+ <ChakraProvider value={system}>+ <Field error="Out of range" label="Seed">+ <Host initialSeed={42} seedMode="fixed" onCommit={vi.fn()} />+ </Field>+ </ChakraProvider>+ );+ });++ const errorId = host.querySelector('[data-part="error-text"]')?.id;++ expect(errorId).toBeTruthy();+ expect(host.querySelector('[data-testid="seed-sequence-preview"]')).toBeNull();+ expect(seedInput()?.getAttribute('aria-describedby')).toBe(errorId);+ });+it('renders an empty field for an absent seed without committing anything', async () => {const onCommit = await renderHost('fixed', undefined);diff --git a/invokeai/frontend/webv2/src/platform/ui/SeedInput.tsx b/invokeai/frontend/webv2/src/platform/ui/SeedInput.tsxindex 4e85a723c7..3802b96df7 100644--- a/invokeai/frontend/webv2/src/platform/ui/SeedInput.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/SeedInput.tsx@@ -2,7 +2,7 @@import type { SeedMode, SeedSubmissionPlan } from '@platform/core/seed';import type { LucideIcon } from 'lucide-react';-import { HStack, Icon, Menu, NumberInput, Portal, Stack, Text } from '@chakra-ui/react';+import { HStack, Icon, Menu, NumberInput, Portal, Stack, Text, useFieldContext } from '@chakra-ui/react';import { SEED_MAX, SEED_MODES } from '@platform/core/seed';import { ChevronDownIcon, DicesIcon, LocateFixedIcon, MinusIcon, PlusIcon, ShuffleIcon } from 'lucide-react';import { useId, useMemo } from 'react';@@ -158,6 +158,10 @@ export const SeedInput = ({const { t } = useTranslation();const previewId = useId();const isRandom = seedMode === 'random';+ // Inside a Field the input is already described by the field's error and helper text; the+ // preview joins that list rather than replacing it.+ const field = useFieldContext();+ const describedBy = [field?.ariaDescribedby, plan ? previewId : undefined].filter(Boolean).join(' ') || undefined;// The host's id goes through zag's id map, never onto the element: zag syncs the DOM value// by looking the input up under its own id, so an overriding `id` leaves an external change// (the dice, a recall, an advance) invisible until the next keystroke.@@ -189,11 +193,7 @@ export const SeedInput = ({}}><NumberInput.Control />- <NumberInput.Input- aria-describedby={plan ? previewId : undefined}- aria-label={ariaLabel}- css={TABULAR_NUMS}- />+ <NumberInput.Input aria-describedby={describedBy} aria-label={ariaLabel} css={TABULAR_NUMS} /></NumberInput.Root>{/* The tooltip is the visible hint; the accessible name stays on the button because atooltip only describes its trigger while open. */}