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(webv2): size segment groups on the button scale

joshistoaste4103e936496
diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/SegmentGroupSizing.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/theme/SegmentGroupSizing.browser.test.tsx
new file mode 100644
index 0000000000..f8e3779a4b
--- /dev/null
+++ b/invokeai/frontend/webv2/src/platform/ui/theme/SegmentGroupSizing.browser.test.tsx
@@ -0,0 +1,58 @@
+import { Button, ChakraProvider, SegmentGroup } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, describe, expect, it } from 'vitest';
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+afterEach(async () => {
+ await act(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+const renderPair = async (size: 'xs' | 'sm' | 'md'): Promise<{ button: HTMLElement; segmentRoot: HTMLElement }> => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+
+ await act(() => {
+ root?.render(
+ <ChakraProvider value={system}>
+ <Button data-testid="button" size={size}>
+ Reference
+ </Button>
+ <SegmentGroup.Root data-testid="segments" size={size} value="a">
+ <SegmentGroup.Indicator />
+ {['a', 'b'].map((value) => (
+ <SegmentGroup.Item key={value} value={value}>
+ <SegmentGroup.ItemHiddenInput />
+ <SegmentGroup.ItemText>{value}</SegmentGroup.ItemText>
+ </SegmentGroup.Item>
+ ))}
+ </SegmentGroup.Root>
+ </ChakraProvider>
+ );
+ });
+
+ return {
+ button: host.querySelector<HTMLElement>('[data-testid="button"]')!,
+ segmentRoot: host.querySelector<HTMLElement>('[data-testid="segments"]')!,
+ };
+};
+
+describe('segmentGroup slot recipe sizing', () => {
+ // Segment groups sit beside buttons in toolbars; a size name must mean the
+ // same outer height on both (Chakra's defaults run one size-name small).
+ (['xs', 'sm', 'md'] as const).forEach((size) => {
+ it(`matches the ${size} button height`, async () => {
+ const { button, segmentRoot } = await renderPair(size);
+
+ expect(segmentRoot.getBoundingClientRect().height).toBeCloseTo(button.getBoundingClientRect().height, 1);
+ });
+ });
+});
diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts b/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts
index 5fb18f9429..c0fefc3ea3 100644
--- a/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts
+++ b/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts
@@ -192,13 +192,34 @@ export const segmentGroupSlotRecipe = defineSlotRecipe({
},
variants: {
...chakraSlotRecipes.segmentGroup.variants,
+ // Item heights are the button height of the same size name minus the
+ // root's 1px border, so a segment group's outer box lands exactly on the
+ // buttons it sits beside — Chakra's defaults run one size-name small
+ // (their `xs` item is button-`2xs` height). Text styles mirror the
+ // button recipe's `xs` cap.
size: {
...chakraSlotRecipes.segmentGroup.variants?.size,
xs: {
- item: { ...chakraSlotRecipes.segmentGroup.variants?.size?.xs?.item, px: '2.5' },
+ item: {
+ ...chakraSlotRecipes.segmentGroup.variants?.size?.xs?.item,
+ height: 'calc({sizes.8} - 2px)',
+ px: '2.5',
+ },
},
sm: {
- item: { ...chakraSlotRecipes.segmentGroup.variants?.size?.sm?.item, px: '3', textStyle: 'xs' },
+ item: {
+ ...chakraSlotRecipes.segmentGroup.variants?.size?.sm?.item,
+ height: 'calc({sizes.9} - 2px)',
+ px: '3.5',
+ textStyle: 'xs',
+ },
+ },
+ md: {
+ item: {
+ ...chakraSlotRecipes.segmentGroup.variants?.size?.md?.item,
+ height: 'calc({sizes.10} - 2px)',
+ textStyle: 'xs',
+ },
},
},
} as unknown as typeof chakraSlotRecipes.segmentGroup.variants,