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(prompts): restore unbounded resizing

joshistoast69cbe2bb6053
diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/ResizableTextarea.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/components/ui/ResizableTextarea.browser.test.tsx
new file mode 100644
index 0000000000..1cf3157858
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/components/ui/ResizableTextarea.browser.test.tsx
@@ -0,0 +1,108 @@
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { PromptTextarea } from '@workbench/widgets/generate/promptFields/PromptTextarea';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import { ResizableTextarea } from './ResizableTextarea';
+
+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 renderTextarea = async (maxHeightPx?: number) => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+ const onResizeEnd = vi.fn();
+
+ await act(() => {
+ root?.render(
+ <ChakraProvider value={system}>
+ <ResizableTextarea
+ aria-label="Prompt"
+ defaultHeightPx={100}
+ maxHeightPx={maxHeightPx}
+ minHeightPx={60}
+ resizeHandleAriaLabel="Resize prompt"
+ onResizeEnd={onResizeEnd}
+ />
+ </ChakraProvider>
+ );
+ });
+
+ return {
+ handle: host.querySelector<HTMLElement>('[role="separator"]')!,
+ onResizeEnd,
+ textarea: host.querySelector<HTMLTextAreaElement>('textarea')!,
+ };
+};
+
+afterEach(async () => {
+ await act(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('ResizableTextarea', () => {
+ it('allows unbounded pointer and keyboard growth while keeping Home at the minimum', async () => {
+ const { handle, onResizeEnd, textarea } = await renderTextarea();
+
+ await act(() => {
+ handle.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'End' }));
+ handle.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowDown' }));
+ });
+ expect(getComputedStyle(textarea).height).toBe('112px');
+
+ await act(() => {
+ handle.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, clientY: 100 }));
+ window.dispatchEvent(new PointerEvent('pointermove', { clientY: 700 }));
+ window.dispatchEvent(new PointerEvent('pointerup'));
+ });
+ expect(getComputedStyle(textarea).height).toBe('712px');
+ expect(onResizeEnd).toHaveBeenLastCalledWith(712);
+
+ await act(() => handle.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'Home' })));
+ expect(getComputedStyle(textarea).height).toBe('60px');
+ expect(handle.hasAttribute('aria-valuemax')).toBe(false);
+ });
+
+ it('retains bounded End behavior when a maximum is supplied', async () => {
+ const { handle, textarea } = await renderTextarea(140);
+
+ await act(() => handle.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'End' })));
+
+ expect(getComputedStyle(textarea).height).toBe('140px');
+ expect(handle.getAttribute('aria-valuemax')).toBe('140');
+ });
+
+ it('uses the legacy prompt font size for both the textarea and syntax underlay', async () => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+
+ await act(() => {
+ root?.render(
+ <ChakraProvider value={system}>
+ <PromptTextarea
+ aria-label="Prompt"
+ defaultHeightPx={100}
+ minHeightPx={60}
+ resizeHandleAriaLabel="Resize prompt"
+ showSyntaxHighlighting
+ value="(sunset:1.2)"
+ onChange={vi.fn()}
+ />
+ </ChakraProvider>
+ );
+ });
+
+ const textarea = host.querySelector<HTMLTextAreaElement>('textarea')!;
+ const underlay = host.querySelector<HTMLElement>('pre')!;
+
+ expect(getComputedStyle(textarea).fontSize).toBe('13.12px');
+ expect(getComputedStyle(underlay).fontSize).toBe('13.12px');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/ResizableTextarea.tsx b/invokeai/frontend/webv2/src/workbench/components/ui/ResizableTextarea.tsx
index 9fede59283..99498f3e02 100644
--- a/invokeai/frontend/webv2/src/workbench/components/ui/ResizableTextarea.tsx
+++ b/invokeai/frontend/webv2/src/workbench/components/ui/ResizableTextarea.tsx
@@ -15,7 +15,11 @@ type TextareaProps = ComponentProps<typeof Textarea>;
const DEFAULT_STEP_PX = 12;
const DEFAULT_LARGE_STEP_PX = 48;
-const clamp = (value: number, min: number, max: number): number => Math.min(Math.max(value, min), max);
+const clamp = (value: number, min: number, max?: number): number => {
+ const minClamped = Math.max(value, min);
+
+ return max === undefined ? minClamped : Math.min(minClamped, max);
+};
const resizeHandleAfter = {
bg: 'border.emphasized',
@@ -50,7 +54,7 @@ export interface ResizableTextareaProps extends Omit<
export const ResizableTextarea = ({
defaultHeightPx,
largeStepPx = DEFAULT_LARGE_STEP_PX,
- maxHeightPx = 420,
+ maxHeightPx,
minHeightPx,
onResizeEnd,
resizeHandleAriaLabel,
@@ -111,7 +115,9 @@ export const ResizableTextarea = ({
: event.key === 'ArrowUp'
? -step
: event.key === 'End'
- ? maxHeightPx - displayHeightPx
+ ? maxHeightPx === undefined
+ ? undefined
+ : maxHeightPx - displayHeightPx
: event.key === 'Home'
? minHeightPx - displayHeightPx
: undefined;
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsx b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsx
index 8f3ce68494..91c02a74e6 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsx
@@ -162,7 +162,6 @@ export const NegativePromptField = ({
{...PROMPT_ATTENTION_TARGET_PROPS}
aria-label={t('widgets.generate.negativePrompt')}
defaultHeightPx={heightPx}
- maxHeightPx={240}
minHeightPx={56}
resizeHandleAriaLabel={t('widgets.generate.resizeNegativePrompt')}
size="xs"
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsx b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsx
index c1042bf286..1629bf1cf0 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsx
@@ -171,7 +171,6 @@ export const PositivePromptField = ({
{...PROMPT_ATTENTION_TARGET_PROPS}
aria-label={t('widgets.generate.positivePrompt')}
defaultHeightPx={heightPx}
- maxHeightPx={360}
minHeightPx={96}
resizeHandleAriaLabel={t('widgets.generate.resizePositivePrompt')}
size="xs"
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PromptTextarea.tsx b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PromptTextarea.tsx
index 674f29543e..9071e72471 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PromptTextarea.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PromptTextarea.tsx
@@ -88,7 +88,7 @@ export const PromptTextarea = ({
const [scroll, setScroll] = useState({ left: 0, top: 0 });
const [textareaClientWidth, setTextareaClientWidth] = useState<number | null>(null);
const shouldHighlight = showSyntaxHighlighting && value.length > 0 && value.length <= MAX_HIGHLIGHTED_PROMPT_LENGTH;
- const effectiveFontSize = fontSize ?? 'xs';
+ const effectiveFontSize = fontSize ?? '0.82rem';
const effectiveLineHeight = lineHeight ?? PROMPT_TEXTAREA_LINE_HEIGHT;
const segments = useMemo(
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
index 07838a83d9..33046c6fc7 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
@@ -336,7 +336,6 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
{...PROMPT_ATTENTION_TARGET_PROPS}
aria-label={t('widgets.layers.regionalGuidance.positivePrompt')}
defaultHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
- maxHeightPx={180}
minHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
placeholder={t('widgets.layers.regionalGuidance.positivePromptPlaceholder')}
resizeHandleAriaLabel={t('widgets.layers.regionalGuidance.positivePrompt')}
@@ -353,7 +352,6 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
{...PROMPT_ATTENTION_TARGET_PROPS}
aria-label={t('widgets.layers.regionalGuidance.negativePrompt')}
defaultHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
- maxHeightPx={180}
minHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
placeholder={t('widgets.layers.regionalGuidance.negativePromptPlaceholder')}
resizeHandleAriaLabel={t('widgets.layers.regionalGuidance.negativePrompt')}