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): make workflow boolean switches toggle
Josh Corbettf41117d1eb57
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsxindex 972dc6b082..a0affc8b21 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx@@ -1,6 +1,6 @@import type { FieldInputTemplate } from '@features/workflow/contracts';-import { ChakraProvider } from '@chakra-ui/react';+import { ChakraProvider, Field } from '@chakra-ui/react';import { DndContext } from '@dnd-kit/core';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { system } from '@theme/system';@@ -263,6 +263,40 @@ const findButton = (label: string): HTMLButtonElement => {};describe('WorkflowFieldInput textarea', () => {+const BOOLEAN_TEMPLATE = {+ name: 'enabled',+ title: 'Enabled',+ type: { batch: false, cardinality: 'SINGLE', name: 'BooleanField' },+} as unknown as FieldInputTemplate;++describe('WorkflowFieldInput boolean', () => {+ it('toggles from a click on the switch when hosted in a Field with an external id', async () => {+ const onChange = vi.fn();++ await act(() => {+ root.render(+ <ChakraProvider value={system}>+ <Field.Root>+ <WorkflowFieldInput id="node-enabled-value" template={BOOLEAN_TEMPLATE} value={false} onChange={onChange} />+ </Field.Root>+ </ChakraProvider>+ );+ });++ const control = host.querySelector('[data-scope="switch"][data-part="control"]');++ if (!(control instanceof HTMLElement)) {+ throw new Error('Switch control not rendered');+ }++ await act(async () => {+ await userEvent.click(control);+ });++ expect(onChange).toHaveBeenCalledWith(true);+ });+});+it('uses the accessible unbounded resizable textarea for prompt-like string fields', async () => {await renderField(TEXTAREA_TEMPLATE, 'hello', vi.fn());diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsxindex 0caea0e7d1..fed56a5ff3 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx@@ -267,20 +267,20 @@ const BooleanInput = ({ id, invalid, onChange, template, value }: WorkflowFieldIsize="sm"onCheckedChange={onCheckedChange}>- <Switch.HiddenInput- aria-label={template.title}- id={id ? `${id}-switch-input` : undefined}- {...invalidProps(invalid)}- />+ <Switch.HiddenInput aria-label={template.title} {...invalidProps(invalid)} /><Switch.Control _checked={SWITCH_CHECKED_PROPS}><Switch.Thumb /></Switch.Control></Switch.Root>+ // The host id goes through zag's id map: the root is a `<label for>` pointing at zag's hidden-input+ // id, so an `id` set on the element itself would leave the label pointing at nothing (an inert switch).+ const switchIds = useMemo(() => (id ? { hiddenInput: `${id}-switch-input` } : undefined), [id]););};const SELECT_VALUE_TEXT_PROPS = { placeholder: 'Select…' };+ ids={switchIds}const SelectInput = ({id,invalid,