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.

feat(schedulers): add searchable comboboxes

joshistoast1cbd6a44fdc7
diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/Combobox.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/components/ui/Combobox.browser.test.tsx
new file mode 100644
index 0000000000..b14b16bcb6
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/components/ui/Combobox.browser.test.tsx
@@ -0,0 +1,144 @@
+/* oxlint-disable react-perf/jsx-no-new-function-as-prop */
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { createInstance } from 'i18next';
+import { act, useState } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { I18nextProvider, initReactI18next } from 'react-i18next';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import { Combobox, type ComboboxOption } from './Combobox';
+
+const options: ComboboxOption[] = [
+ { label: 'Euler Ancestral', value: 'euler_a' },
+ { label: 'DPM++ 2M', value: 'dpmpp_2m' },
+ { label: 'UniPC', value: 'unipc' },
+];
+
+const i18n = createInstance();
+void i18n.use(initReactI18next).init({
+ fallbackLng: 'en',
+ initImmediate: false,
+ lng: 'en',
+ resources: {
+ en: {
+ translation: {
+ common: {
+ noSchedulersFound: 'No schedulers found',
+ openSelector: 'Open selector',
+ searchSchedulers: 'Search schedulers…',
+ },
+ },
+ },
+ },
+});
+
+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 interact = (action: () => void): Promise<void> =>
+ act(async () => {
+ action();
+ await new Promise<void>((resolve) => {
+ globalThis.setTimeout(resolve, 50);
+ });
+ });
+
+const Harness = ({ disabled = false, onChange }: { disabled?: boolean; onChange: (value: string) => void }) => {
+ const [value, setValue] = useState('euler_a');
+
+ return (
+ <Combobox
+ aria-label="Scheduler"
+ disabled={disabled}
+ options={options}
+ value={value}
+ onValueChange={(nextValue) => {
+ setValue(nextValue);
+ onChange(nextValue);
+ }}
+ />
+ );
+};
+
+const renderCombobox = async (disabled = false) => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+ const onChange = vi.fn();
+
+ await interact(() => {
+ root?.render(
+ <I18nextProvider i18n={i18n}>
+ <ChakraProvider value={system}>
+ <Harness disabled={disabled} onChange={onChange} />
+ </ChakraProvider>
+ </I18nextProvider>
+ );
+ });
+
+ return { input: host.querySelector<HTMLInputElement>('input[role="combobox"]')!, onChange };
+};
+
+const setInputValue = async (input: HTMLInputElement, value: string) => {
+ const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
+
+ await interact(() => {
+ valueSetter?.call(input, value);
+ input.dispatchEvent(new InputEvent('input', { bubbles: true, data: value, inputType: 'insertText' }));
+ });
+};
+
+afterEach(async () => {
+ await interact(() => root?.unmount());
+ document.querySelectorAll('[data-scope="combobox"][data-part="positioner"]').forEach((element) => element.remove());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('Combobox', () => {
+ it('filters labels and values case-insensitively and reports empty results', async () => {
+ const { input } = await renderCombobox();
+
+ expect(input.value).toBe('Euler Ancestral');
+ await interact(() => input.click());
+ await setInputValue(input, 'DPM');
+ expect(document.querySelectorAll('[role="option"]')).toHaveLength(1);
+ expect(document.querySelector('[role="option"]')?.textContent).toContain('DPM++ 2M');
+
+ await setInputValue(input, 'not-a-scheduler');
+ expect(document.body.textContent).toContain('No schedulers found');
+ });
+
+ it('supports controlled mouse and keyboard selection with selected-state indication', async () => {
+ const { input, onChange } = await renderCombobox();
+
+ await interact(() => input.click());
+ expect(document.querySelector('[role="option"][data-state="checked"]')?.textContent).toContain('Euler Ancestral');
+ const unipc = Array.from(document.querySelectorAll<HTMLElement>('[role="option"]')).find((option) =>
+ option.textContent?.includes('UniPC')
+ );
+ await interact(() => unipc?.click());
+ expect(onChange).toHaveBeenLastCalledWith('unipc');
+ expect(input.value).toBe('UniPC');
+
+ await interact(() => input.click());
+ await setInputValue(input, 'euler');
+ await interact(() => {
+ input.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowDown' }));
+ input.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'Enter' }));
+ });
+ expect(onChange).toHaveBeenLastCalledWith('euler_a');
+ expect(input.value).toBe('Euler Ancestral');
+ });
+
+ it('honors the disabled state', async () => {
+ const { input } = await renderCombobox(true);
+
+ expect(input.disabled).toBe(true);
+ await interact(() => input.click());
+ expect(input.getAttribute('aria-expanded')).toBe('false');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/Combobox.tsx b/invokeai/frontend/webv2/src/workbench/components/ui/Combobox.tsx
new file mode 100644
index 0000000000..70dee18682
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/components/ui/Combobox.tsx
@@ -0,0 +1,150 @@
+import type {
+ ComboboxInputProps,
+ ComboboxRootProps,
+ ComboboxValueChangeDetails,
+ CollectionItem,
+} from '@chakra-ui/react';
+
+import { Combobox as ChakraCombobox, createListCollection, Portal } from '@chakra-ui/react';
+import { CheckIcon, ChevronDownIcon } from 'lucide-react';
+import { useCallback, useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+const COMBOBOX_POSITIONING = { placement: 'bottom-start', sameWidth: true } as const;
+
+export interface ComboboxOption extends CollectionItem {
+ disabled?: boolean;
+ label: string;
+ value: string;
+}
+
+export interface ComboboxProps extends Omit<
+ ComboboxRootProps<ComboboxOption>,
+ | 'allowCustomValue'
+ | 'collection'
+ | 'inputValue'
+ | 'multiple'
+ | 'onInputValueChange'
+ | 'onOpenChange'
+ | 'onValueChange'
+ | 'open'
+ | 'value'
+> {
+ inputProps?: ComboboxInputProps;
+ noResultsText?: string;
+ options: readonly ComboboxOption[];
+ searchPlaceholder?: string;
+ value: string | null;
+ onValueChange: (value: string) => void;
+}
+
+/** Controlled, single-value searchable picker with workbench-standard portal positioning. */
+export const Combobox = ({
+ 'aria-label': ariaLabel,
+ inputProps,
+ noResultsText,
+ onValueChange,
+ options,
+ searchPlaceholder,
+ value,
+ ...rootProps
+}: ComboboxProps) => {
+ const { t } = useTranslation();
+ const [isOpen, setIsOpen] = useState(false);
+ const [query, setQuery] = useState('');
+ const selectedLabel = options.find((option) => option.value === value)?.label ?? '';
+ const normalizedQuery = query.trim().toLocaleLowerCase();
+ const selectedValues = useMemo(() => (value ? [value] : []), [value]);
+ const filteredOptions = useMemo(
+ () =>
+ normalizedQuery === ''
+ ? options
+ : options.filter(
+ (option) =>
+ option.label.toLocaleLowerCase().includes(normalizedQuery) ||
+ option.value.toLocaleLowerCase().includes(normalizedQuery)
+ ),
+ [normalizedQuery, options]
+ );
+ const collection = useMemo(
+ () =>
+ createListCollection({
+ items: filteredOptions,
+ isItemDisabled: (item) => item.disabled === true,
+ itemToString: (item) => item.label,
+ itemToValue: (item) => item.value,
+ }),
+ [filteredOptions]
+ );
+ const handleOpenChange = useCallback((details: { open: boolean }) => {
+ setIsOpen(details.open);
+ setQuery('');
+ }, []);
+ const handleInputValueChange = useCallback((details: { inputValue: string; reason?: string }) => {
+ if (details.reason === 'input-change' || details.reason === 'clear-trigger') {
+ setQuery(details.inputValue);
+ }
+ }, []);
+ const handleValueChange = useCallback(
+ (details: ComboboxValueChangeDetails<ComboboxOption>) => {
+ const nextValue = details.value[0];
+
+ if (nextValue !== undefined) {
+ onValueChange(nextValue);
+ }
+ },
+ [onValueChange]
+ );
+
+ return (
+ <ChakraCombobox.Root
+ {...rootProps}
+ allowCustomValue={false}
+ closeOnSelect
+ collection={collection}
+ inputBehavior="autohighlight"
+ inputValue={isOpen ? query : selectedLabel}
+ multiple={false}
+ open={isOpen}
+ openOnClick
+ positioning={COMBOBOX_POSITIONING}
+ selectionBehavior="replace"
+ value={selectedValues}
+ onInputValueChange={handleInputValueChange}
+ onOpenChange={handleOpenChange}
+ onValueChange={handleValueChange}
+ >
+ <ChakraCombobox.Control>
+ <ChakraCombobox.Input
+ {...inputProps}
+ aria-label={inputProps?.['aria-label'] ?? ariaLabel}
+ placeholder={searchPlaceholder ?? t('common.searchSchedulers')}
+ />
+ <ChakraCombobox.IndicatorGroup>
+ <ChakraCombobox.Trigger aria-label={t('common.openSelector')}>
+ <ChevronDownIcon />
+ </ChakraCombobox.Trigger>
+ </ChakraCombobox.IndicatorGroup>
+ </ChakraCombobox.Control>
+ <Portal>
+ <ChakraCombobox.Positioner>
+ <ChakraCombobox.Content>
+ <ChakraCombobox.List maxH="16rem" overflowY="auto">
+ {collection.items.map((item) => (
+ <ChakraCombobox.Item key={item.value} item={item}>
+ <ChakraCombobox.ItemText>{item.label}</ChakraCombobox.ItemText>
+ <ChakraCombobox.ItemIndicator>
+ <CheckIcon />
+ </ChakraCombobox.ItemIndicator>
+ </ChakraCombobox.Item>
+ ))}
+ <ChakraCombobox.Empty color="fg.muted" fontSize="xs" px="3" py="2">
+ {noResultsText ?? t('common.noSchedulersFound')}
+ </ChakraCombobox.Empty>
+ </ChakraCombobox.List>
+ </ChakraCombobox.Content>
+ </ChakraCombobox.Positioner>
+ </Portal>
+ </ChakraCombobox.Root>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/index.ts b/invokeai/frontend/webv2/src/workbench/components/ui/index.ts
index 1e10a8129f..50e2702632 100644
--- a/invokeai/frontend/webv2/src/workbench/components/ui/index.ts
+++ b/invokeai/frontend/webv2/src/workbench/components/ui/index.ts
@@ -1,5 +1,6 @@
export * from './Button';
export * from './ColorPicker';
+export * from './Combobox';
export * from './ConfirmDialog';
export * from './Field';
export * from './JsonPreview';
diff --git a/invokeai/frontend/webv2/src/workbench/launchpad/models/detail/DefaultSettingsSection.tsx b/invokeai/frontend/webv2/src/workbench/launchpad/models/detail/DefaultSettingsSection.tsx
index 1ecaf6362a..c4f3cfb972 100644
--- a/invokeai/frontend/webv2/src/workbench/launchpad/models/detail/DefaultSettingsSection.tsx
+++ b/invokeai/frontend/webv2/src/workbench/launchpad/models/detail/DefaultSettingsSection.tsx
@@ -3,7 +3,7 @@ import type { AnyModelDefaultSettings, ModelConfig } from '@workbench/models/typ
import type { TFunction } from 'i18next';
import { Grid, HStack, Icon, NativeSelect, NumberInput, Stack, Switch, Text } from '@chakra-ui/react';
-import { Button, FieldLabel, Panel } from '@workbench/components/ui';
+import { Button, Combobox, FieldLabel, Panel } from '@workbench/components/ui';
import { updateModel } from '@workbench/models/api';
import { replaceModelInStore } from '@workbench/models/modelsStore';
import { loraDefaultSettingsSchema, mainDefaultSettingsSchema } from '@workbench/models/schemas';
@@ -49,6 +49,7 @@ const SCHEDULERS = [
'unipc',
'unipc_k',
];
+const SCHEDULER_OPTIONS = SCHEDULERS.map((scheduler) => ({ label: scheduler, value: scheduler }));
const CONTROL_ADAPTER_TYPES = new Set(['controlnet', 't2i_adapter', 'control_lora']);
@@ -83,7 +84,7 @@ interface FieldSpec {
key: keyof AnyModelDefaultSettings;
labelKey: string;
/** Render the control; disabled (showing the inherited value) until customized. */
- control: (value: unknown, setValue: (value: unknown) => void, disabled: boolean) => ReactNode;
+ control: (value: unknown, setValue: (value: unknown) => void, disabled: boolean, label: string) => ReactNode;
/** Value used when the toggle is switched on; also previewed while off. */
defaultValue: unknown;
/** Translation key for what applies while the toggle is off. */
@@ -92,7 +93,7 @@ interface FieldSpec {
const numberControl =
(props: { max?: number; min?: number; step?: number }) =>
- (value: unknown, setValue: (value: unknown) => void, disabled: boolean) => (
+ (value: unknown, setValue: (value: unknown) => void, disabled: boolean, _label: string) => (
<NumberInput.Root
disabled={disabled}
max={props.max}
@@ -129,7 +130,7 @@ const numberControl =
);
const selectControl =
- (options: string[]) => (value: unknown, setValue: (value: unknown) => void, disabled: boolean) => (
+ (options: string[]) => (value: unknown, setValue: (value: unknown) => void, disabled: boolean, _label: string) => (
<NativeSelect.Root disabled={disabled} size="sm">
<NativeSelect.Field
value={typeof value === 'string' ? value : ''}
@@ -145,9 +146,22 @@ const selectControl =
</NativeSelect.Root>
);
+const schedulerControl =
+ (options: { label: string; value: string }[]) =>
+ (value: unknown, setValue: (value: unknown) => void, disabled: boolean, label: string) => (
+ <Combobox
+ aria-label={label}
+ disabled={disabled}
+ options={options}
+ size="sm"
+ value={typeof value === 'string' ? value : null}
+ onValueChange={setValue}
+ />
+ );
+
const MAIN_FIELDS: FieldSpec[] = [
{
- control: selectControl(SCHEDULERS),
+ control: schedulerControl(SCHEDULER_OPTIONS),
defaultValue: 'euler_a',
inheritLabelKey: 'models.defaultFieldInherited.scheduler',
key: 'scheduler',
@@ -375,7 +389,8 @@ export const DefaultSettingsSection = ({
{field.control(
isEnabled ? value : field.defaultValue,
(nextValue) => setFieldValue(field.key, nextValue),
- !isEnabled
+ !isEnabled,
+ t(field.labelKey)
)}
<Text color="fg.subtle" fontSize="2xs">
{isEnabled ? t('models.customizedForThisModel') : t(field.inheritLabelKey)}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/generate/GenerateModelFields.tsx b/invokeai/frontend/webv2/src/workbench/widgets/generate/GenerateModelFields.tsx
index 1a855a0e63..8b4ddf67f4 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/generate/GenerateModelFields.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/generate/GenerateModelFields.tsx
@@ -1,10 +1,9 @@
/* oxlint-disable react-perf/jsx-no-new-object-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-jsx-as-prop */
import type { GenerateModelConfig, GenerateSettings, VaeModelConfig } from '@workbench/generation/types';
import type { ModelConfig } from '@workbench/models/types';
-import type { ChangeEvent } from 'react';
-import { HStack, Icon, InputGroup, NativeSelect, NumberInput, Stack } from '@chakra-ui/react';
-import { Button, IconButton, Field, Tooltip } from '@workbench/components/ui';
+import { HStack, Icon, InputGroup, NumberInput, Stack } from '@chakra-ui/react';
+import { Button, Combobox, IconButton, Field, Tooltip } from '@workbench/components/ui';
import {
getDefaultGenerateSettings,
getGenerationModelPolicy,
@@ -209,22 +208,14 @@ export const GenerateModelFields = ({
{policy.ui.schedulerVisible ? (
<Field label={t('widgets.generate.scheduler')}>
<HStack gap="1">
- <NativeSelect.Root flex="1" size="xs">
- <NativeSelect.Field
- aria-label={t('widgets.generate.scheduler')}
- value={settings.scheduler}
- onChange={(event: ChangeEvent<HTMLSelectElement>) =>
- onCommit({ scheduler: event.currentTarget.value })
- }
- >
- {policy.scheduler.options.map((option) => (
- <option key={option.value} value={option.value}>
- {option.label}
- </option>
- ))}
- </NativeSelect.Field>
- <NativeSelect.Indicator />
- </NativeSelect.Root>
+ <Combobox
+ aria-label={t('widgets.generate.scheduler')}
+ flex="1"
+ options={policy.scheduler.options}
+ size="xs"
+ value={settings.scheduler}
+ onValueChange={(scheduler) => onCommit({ scheduler })}
+ />
<ModelDefaultButton
disabled={!modelDefaults || settings.scheduler === modelDefaults.scheduler}
label={t('widgets.generate.useModelDefaultScheduler')}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/workflow/fields/WorkflowFieldInput.tsx b/invokeai/frontend/webv2/src/workbench/widgets/workflow/fields/WorkflowFieldInput.tsx
index 30f1fc3261..420f43a92c 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/workflow/fields/WorkflowFieldInput.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/workflow/fields/WorkflowFieldInput.tsx
@@ -3,7 +3,7 @@ import type { GeneratedImageContract } from '@workbench/types';
import type { FieldInputTemplate } from '@workbench/workflows/types';
import { HStack, Input, NativeSelect, Switch, Text, Textarea } from '@chakra-ui/react';
-import { Button } from '@workbench/components/ui';
+import { Button, Combobox } from '@workbench/components/ui';
import { listGalleryBoards, type GalleryBoard } from '@workbench/gallery/api';
import { SCHEDULER_OPTIONS } from '@workbench/generation/baseGenerationPolicies';
import { ModelSelect } from '@workbench/models/components';
@@ -192,6 +192,21 @@ const EnumInput = ({ id, invalid, onChange, template, value }: WorkflowFieldInpu
[template.options, template.uiChoiceLabels]
);
+ if (template.name === 'scheduler') {
+ return (
+ <Combobox
+ aria-label={template.title}
+ className="nodrag nowheel"
+ id={id ? `${id}-scheduler-combobox` : undefined}
+ invalid={invalid}
+ options={options}
+ size="xs"
+ value={typeof value === 'string' ? value : null}
+ onValueChange={onChange}
+ />
+ );
+ }
+
return (
<SelectInput id={id} invalid={invalid} options={options} title={template.title} value={value} onChange={onChange} />
);
@@ -232,13 +247,15 @@ const ModelIdentifierInput = ({ id, invalid, onChange, template, value }: Workfl
};
const SchedulerInput = ({ id, invalid, onChange, template, value }: WorkflowFieldInputProps) => (
- <SelectInput
- id={id}
+ <Combobox
+ aria-label={template.title}
+ className="nodrag nowheel"
+ id={id ? `${id}-scheduler-combobox` : undefined}
invalid={invalid}
options={SCHEDULER_OPTIONS}
- title={template.title}
- value={value}
- onChange={onChange}
+ size="xs"
+ value={typeof value === 'string' ? value : null}
+ onValueChange={onChange}
/>
);