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(ui): hide list dividers beside a hovered row

Josh Corbett64958002d353
diff --git a/invokeai/frontend/webv2/src/platform/ui/list/List.tsx b/invokeai/frontend/webv2/src/platform/ui/list/List.tsx
index 64db229bfd..de902c5552 100644
--- a/invokeai/frontend/webv2/src/platform/ui/list/List.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/list/List.tsx
@@ -10,7 +10,7 @@ import { useTranslation } from 'react-i18next';
import type { ListDensity } from './ListItem';
import type { ListRow } from './listRows';
-import { ListDivider } from './ListDivider';
+import { IN_SLOT_DIVIDER_HIDING_CSS, ListDivider } from './ListDivider';
import { LIST_ROW_GAP_PX as ROW_GAP_PX, LIST_ROW_INSET as INSET } from './listLayout';
import { LIST_SECTION_HEADER_HEIGHT_PX, ListSectionHeader } from './ListSectionHeader';
@@ -432,7 +432,13 @@ export const List = <T,>({
} else {
content = (
<Scrollable h="full" viewportProps={viewportProps} viewportRef={attachViewport}>
- <div aria-busy={isBusy || undefined} aria-label={label} role="list" style={containerStyle}>
+ <Box
+ aria-busy={isBusy || undefined}
+ aria-label={label}
+ css={dividers ? IN_SLOT_DIVIDER_HIDING_CSS : undefined}
+ role="list"
+ style={containerStyle}
+ >
{virtualItems.map((virtualRow) => {
const row = rows[virtualRow.index];
@@ -482,7 +488,7 @@ export const List = <T,>({
</div>
);
})}
- </div>
+ </Box>
</Scrollable>
);
}
diff --git a/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx
index b65a2a93fa..7959fc4003 100644
--- a/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx
@@ -4,6 +4,7 @@ import { system } from '@theme/system';
import { act, type ReactElement } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { userEvent } from 'vitest/browser';
import { List, type ListRowProps } from './List';
import { ListItem } from './ListItem';
@@ -216,4 +217,67 @@ describe('list dividers', () => {
expect(line.left - rowA.left).toBeCloseTo(8, 0);
expect(rowA.right - line.right).toBeCloseTo(8, 0);
});
+
+ it('hides the hairlines either side of a pointed row, stacked or virtualized', async () => {
+ const opacities = () =>
+ [...host.querySelectorAll<HTMLElement>('[data-list-divider]')].map((line) => getComputedStyle(line).opacity);
+
+ await render(
+ <ListStack dividers label="subjects">
+ <ListItem title="one" />
+ <ListItem title="two" />
+ <ListItem title="three" />
+ <ListItem title="four" />
+ </ListStack>
+ );
+ const stacked = host.querySelectorAll<HTMLElement>('[role="listitem"]');
+
+ await userEvent.hover(stacked[1]!);
+ await expect.poll(opacities).toEqual(['0', '0', '1']);
+ await render(
+ <ListStack dividers label="subjects">
+ <ListItem isMenuOpen title="one" />
+ <ListItem title="two" />
+ <ListItem title="three" />
+ <ListItem title="four" />
+ </ListStack>
+ );
+ await userEvent.unhover(host);
+ await expect.poll(opacities).toEqual(['0', '1', '1']);
+
+ // A caller-wrapped row (its own list item around the row) holding an open menu.
+ await render(
+ <ListStack dividers label="subjects">
+ <ListItem title="one" />
+ <div role="listitem">
+ <ListItem isMenuOpen role="presentation" title="two" />
+ </div>
+ <ListItem title="three" />
+ <ListItem title="four" />
+ </ListStack>
+ );
+ await expect.poll(opacities).toEqual(['0', '0', '1']);
+
+ const rows = listRowsFromSections(
+ [{ items: [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }], key: 'one', label: 'One' }],
+ (item) => item.id
+ );
+
+ await render(
+ <List
+ dividers
+ label="subjects"
+ renderItem={(item: { id: string }, rowProps: ListRowProps) => <ListItem {...rowProps} title={item.id} />}
+ rows={rows}
+ />
+ );
+ await act(async () => {
+ await new Promise((resolve) => {
+ requestAnimationFrame(() => resolve(undefined));
+ });
+ });
+
+ await userEvent.hover(host.querySelector<HTMLElement>('[data-list-row="c"]')!);
+ await expect.poll(opacities).toEqual(['1', '0', '0']);
+ });
});
diff --git a/invokeai/frontend/webv2/src/platform/ui/list/ListDivider.tsx b/invokeai/frontend/webv2/src/platform/ui/list/ListDivider.tsx
index 560bb1f36a..c34f36d4b1 100644
--- a/invokeai/frontend/webv2/src/platform/ui/list/ListDivider.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/list/ListDivider.tsx
@@ -14,6 +14,7 @@ const HAIRLINE = {
borderTopStyle: 'solid',
borderTopWidth: `${HAIRLINE_PX}px`,
h: 0,
+ transition: 'opacity var(--wb-motion-duration-fast) ease',
} as const;
const IN_FLOW_CSS = {
@@ -32,7 +33,31 @@ const IN_SLOT_CSS = {
position: 'absolute',
} as const;
+// A row shows its pointed fill while hovered or while its context menu is open; the hairlines either side of it hide
+// so that fill reads as one surface rather than a band between lines. `:has()` cannot nest, so a row wrapped by its
+// caller (menu state on a descendant) is matched as "a sibling containing it" instead.
+const POINTED = ':is(:hover, [data-menu-open])';
+const HIDDEN = { opacity: 0 } as const;
+
+/** For a container of in-flow rows and dividers (`ListStack`); rows may be wrapped by their caller. */
+export const IN_FLOW_DIVIDER_HIDING_CSS = {
+ [[
+ `& > ${POINTED} + [data-list-divider]`,
+ '& > :has([data-menu-open]) + [data-list-divider]',
+ `& > [data-list-divider]:has(+ ${POINTED})`,
+ '& > [data-list-divider]:has(+ * [data-menu-open])',
+ ].join(', ')]: HIDDEN,
+} as const;
+
+/** For a container of row slots that each draw the divider below themselves (`List`). */
+export const IN_SLOT_DIVIDER_HIDING_CSS = {
+ [[
+ `& > :has([data-list-row]${POINTED}) > [data-list-divider]`,
+ `& > :has(+ * [data-list-row]${POINTED}) > [data-list-divider]`,
+ ].join(', ')]: HIDDEN,
+} as const;
+
/** Hairline between two rows; decorative, so hidden from assistive tech. */
export const ListDivider = ({ placement }: { placement: 'in-flow' | 'in-slot' }) => (
- <chakra.div aria-hidden css={placement === 'in-flow' ? IN_FLOW_CSS : IN_SLOT_CSS} />
+ <chakra.div aria-hidden css={placement === 'in-flow' ? IN_FLOW_CSS : IN_SLOT_CSS} data-list-divider="" />
);
diff --git a/invokeai/frontend/webv2/src/platform/ui/list/ListStack.tsx b/invokeai/frontend/webv2/src/platform/ui/list/ListStack.tsx
index 8a82ed0e1b..2c65b82951 100644
--- a/invokeai/frontend/webv2/src/platform/ui/list/ListStack.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/list/ListStack.tsx
@@ -3,7 +3,7 @@ import type { ReactNode } from 'react';
import { Stack, type StackProps } from '@chakra-ui/react';
import { Children } from 'react';
-import { ListDivider } from './ListDivider';
+import { IN_FLOW_DIVIDER_HIDING_CSS, ListDivider } from './ListDivider';
import { LIST_ROW_GAP_PX } from './listLayout';
export interface ListStackProps extends Omit<StackProps, 'children' | 'gap' | 'role'> {
@@ -20,7 +20,13 @@ export interface ListStackProps extends Omit<StackProps, 'children' | 'gap' | 'r
* virtualizes. Rows keep the family's spacing either way.
*/
export const ListStack = ({ children, dividers = false, label, ...stackProps }: ListStackProps) => (
- <Stack aria-label={label} gap={dividers ? 0 : `${LIST_ROW_GAP_PX}px`} role="list" {...stackProps}>
+ <Stack
+ aria-label={label}
+ css={dividers ? IN_FLOW_DIVIDER_HIDING_CSS : undefined}
+ gap={dividers ? 0 : `${LIST_ROW_GAP_PX}px`}
+ role="list"
+ {...stackProps}
+ >
{dividers
? Children.toArray(children).flatMap((row, index) =>
// Dividers carry no state, so index keys are safe for them.