Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(filters): standardize multiselect dropdown interactions (#8678)

dev-rb07357694c4c5
diff --git a/.agents/rules/web/ui.md b/.agents/rules/web/ui.md
index 20a280ee85..92c88da3f6 100644
--- a/.agents/rules/web/ui.md
+++ b/.agents/rules/web/ui.md
@@ -62,6 +62,9 @@ Components, styling, and interaction conventions.
whenever one fits; browse them at `/app/component/ui`. Don't build a one-off
button, dialog, menu, or input. A missing primitive is added there, with a
`*.docs.tsx` page and tests, not inside a feature.
+- Use `Dropdown.MultiSelectItem` for multiselect filter rows; keep independent
+ checkbox settings on `Dropdown.CheckboxItem`. Follow the
+ [shared interaction pattern](../../../docs/agent-guide/ui-conventions.md#multiselect-dropdowns).
- **FE-54** Decide mobile behavior deliberately. Unless the change makes it
obvious, ask the user how a UI change should look and behave on mobile, then
follow [`mobile.md`](mobile.md).
diff --git a/CODING.md b/CODING.md
index 680b81bc73..f66eede28b 100644
--- a/CODING.md
+++ b/CODING.md
@@ -25,6 +25,7 @@ files; the [style guide](docs/development/style-guide.md) indexes them.
- Use native APIs and existing libraries. No polyfills, no homemade crypto.
- Keep types and traits small.
- Name things for what they are. No jargon or slang.
+- Use explicit branches instead of deeply nested ternaries.
- Compatibility only at deployed boundaries (migrations, persisted formats).
## Correctness
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 45f37e62ef..d59c9b75de 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -196,6 +196,9 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.
names; completed step snapshots come from the shared fold of the tool receipt.
Session `ExecuteCode` activity uses the same Calling N tools peek window as
ordinary consecutive tool calls.
+- Compose multiselect filters with `Dropdown.MultiSelectItem` and the shared
+ searchable filters; follow [multiselect dropdowns](../../docs/agent-guide/ui-conventions.md#multiselect-dropdowns)
+ for checkbox, row, Only, keyboard, and touch behavior.
- All API/network calls live in service-clients.
- Open projects through `openProject` (`features/projects/open-project.ts`): it
retargets an already-open project split to the section or comment in place.
diff --git a/apps/web/src/components/ui/components/Dropdown.docs.tsx b/apps/web/src/components/ui/components/Dropdown.docs.tsx
new file mode 100644
index 0000000000..e0d9b16d17
--- /dev/null
+++ b/apps/web/src/components/ui/components/Dropdown.docs.tsx
@@ -0,0 +1,63 @@
+import { defineDoc } from '@app/features/ui-gallery/types';
+import { createSignal, For } from 'solid-js';
+import { Dropdown } from './Dropdown';
+
+// #region demo:multiselect
+function MultiselectDemo() {
+ const [selected, setSelected] = createSignal(['Docs']);
+ return (
+ <div class="flex flex-col items-start gap-3">
+ <Dropdown>
+ <Dropdown.Trigger>Filter types</Dropdown.Trigger>
+ <Dropdown.Content class="min-w-56">
+ <Dropdown.Group>
+ <For each={['Docs', 'Tasks', 'Mail']}>
+ {(label) => (
+ <Dropdown.MultiSelectItem
+ label={label}
+ checked={selected().includes(label)}
+ onChange={(checked) =>
+ setSelected((values) =>
+ checked
+ ? values.includes(label)
+ ? values
+ : [...values, label]
+ : values.filter((value) => value !== label)
+ )
+ }
+ onOnly={() => setSelected([label])}
+ >
+ <span class="flex-1 truncate">{label}</span>
+ </Dropdown.MultiSelectItem>
+ )}
+ </For>
+ </Dropdown.Group>
+ </Dropdown.Content>
+ </Dropdown>
+ <p class="text-xs text-ink-muted">
+ Selected: {selected().join(', ') || 'None'}
+ </p>
+ </div>
+ );
+}
+// #endregion
+
+export default defineDoc({
+ name: 'Dropdown',
+ category: 'Overlays',
+ description:
+ 'Menus with shared keyboard navigation. Multiselect rows distinguish toggling, adding, and selecting only one option.',
+ status: 'stable',
+ import: "import { Dropdown } from '@ui';",
+ exports: ['Dropdown'],
+ propTypes: ['DropdownMultiSelectItemProps'],
+ demos: [
+ {
+ id: 'multiselect',
+ title: 'Multiselect filters',
+ description:
+ 'Checkbox or Space toggles and stays open. Row or Enter adds and closes. Shift-click, Shift+Enter, or Only selects just one and stays open. Only is always visible on touch.',
+ render: MultiselectDemo,
+ },
+ ],
+});
diff --git a/apps/web/src/components/ui/components/Dropdown.tsx b/apps/web/src/components/ui/components/Dropdown.tsx
index c1caf7abe1..7ed5c0a935 100644
--- a/apps/web/src/components/ui/components/Dropdown.tsx
+++ b/apps/web/src/components/ui/components/Dropdown.tsx
@@ -15,11 +15,13 @@ import {
addCtrlJKMenuNavigation,
highlightFirstMenuItemOnOpen,
} from '../utils/menuKeyboardNavigation';
+import { createMultiSelectIntent } from '../utils/multiSelectSelection';
import {
createSelectionDismissal,
type SelectionDismissal,
} from '../utils/selectionDismissal';
import { Button, type ButtonProps } from './Button';
+import { MultiSelectItemContent } from './MultiSelectItemContent';
import { Surface, type SurfaceProps } from './Surface';
/*
@@ -97,6 +99,15 @@ export type DropdownItemProps = Omit<
> & {
closeOnSelect?: SelectionDismissal;
};
+export type DropdownMultiSelectItemProps = Omit<
+ DropdownItemProps,
+ 'onSelect' | 'closeOnSelect'
+> & {
+ checked: boolean;
+ label: string;
+ onChange: (checked: boolean) => void;
+ onOnly: () => void;
+};
export type DropdownSubProps = ComponentProps<typeof KobalteDropdownMenu.Sub>;
// Text size is inherited from `Dropdown.Content` (defaults to `text-sm`) so a
@@ -368,6 +379,56 @@ function DropdownCheckboxItem(props: DropdownCheckboxItemProps) {
);
}
+/**
+ * Checkbox/Space toggles without closing; row/Enter adds and closes.
+ * Shift activation and Only replace the group selection without closing.
+ *
+ * @do Use for options in a multiselect filter, not independent settings.
+ * @do Replace only this item's group in `onOnly`, preserving other filters.
+ */
+function DropdownMultiSelectItem(props: DropdownMultiSelectItemProps) {
+ const selectionIntent = createMultiSelectIntent();
+ const [local, rest] = splitProps(props, [
+ 'checked',
+ 'label',
+ 'onChange',
+ 'onOnly',
+ 'class',
+ 'children',
+ 'ref',
+ ]);
+ return (
+ <KobalteDropdownMenu.Item
+ {...rest}
+ role="menuitemcheckbox"
+ aria-label={local.label}
+ aria-checked={local.checked}
+ textValue={local.label}
+ aria-keyshortcuts="Space Enter Shift+Enter"
+ class={cn(ROW_CLASS, 'relative pr-14 touch:min-h-11', local.class)}
+ ref={(element) => {
+ selectionIntent.track(element);
+ callRef(local.ref, element);
+ }}
+ closeOnSelect={selectionIntent.shouldClose()}
+ onSelect={() => {
+ if (selectionIntent.intent() === 'only') local.onOnly();
+ else
+ local.onChange(selectionIntent.intent() === 'add' || !local.checked);
+ }}
+ >
+ <MultiSelectItemContent
+ checked={local.checked}
+ label={local.label}
+ disabled={rest.disabled}
+ onOnly={local.onOnly}
+ >
+ {local.children}
+ </MultiSelectItemContent>
+ </KobalteDropdownMenu.Item>
+ );
+}
+
function DropdownItemIndicator(props: DropdownItemIndicatorProps) {
return <KobalteDropdownMenu.ItemIndicator {...props} />;
}
@@ -442,6 +503,7 @@ export const Dropdown = Object.assign(
ItemDescription:
KobalteDropdownMenu.ItemDescription /* passthrough — describes the item for assistive tech */,
CheckboxItem: DropdownCheckboxItem,
+ MultiSelectItem: DropdownMultiSelectItem,
SubContent: DropdownSubContent,
SubTrigger: DropdownSubTrigger,
GroupLabel: DropdownGroupLabel,
diff --git a/apps/web/src/components/ui/components/MultiSelectItemContent.tsx b/apps/web/src/components/ui/components/MultiSelectItemContent.tsx
new file mode 100644
index 0000000000..1c8b281751
--- /dev/null
+++ b/apps/web/src/components/ui/components/MultiSelectItemContent.tsx
@@ -0,0 +1,51 @@
+import type { JSX } from 'solid-js';
+import { Button } from './Button';
+import { InlineCheckbox } from './Checkbox';
+
+/** Shared affordances for menu and searchable multiselect rows. */
+export function MultiSelectItemContent(props: {
+ checked: boolean;
+ label: string;
+ disabled?: boolean;
+ onOnly: () => void;
+ onlyLabel?: 'Only' | 'All';
+ children: JSX.Element;
+}) {
+ return (
+ <>
+ <span
+ aria-hidden="true"
+ data-multiselect-checkbox
+ class="-my-1.5 -ml-2 inline-flex self-stretch items-center pl-2 pr-1 touch:min-h-11 touch:min-w-9"
+ >
+ <InlineCheckbox checked={props.checked} />
+ </span>
+ {props.children}
+ <Button
+ variant="ghost"
+ size="xs"
+ tabIndex={-1}
+ disabled={props.disabled}
+ aria-label={
+ props.onlyLabel === 'All'
+ ? 'Select all'
+ : `Select only ${props.label}`
+ }
+ class="absolute right-1 top-1/2 -translate-y-1/2 opacity-0 pointer-events-none not-touch:group-hover:opacity-100 not-touch:group-hover:pointer-events-auto group-data-highlighted:opacity-100 group-data-highlighted:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto touch:opacity-100 touch:pointer-events-auto"
+ onPointerDown={(event) => {
+ event.preventDefault();
+ event.stopPropagation();
+ }}
+ onPointerUp={(event) => event.stopPropagation()}
+ onMouseDown={(event) => event.preventDefault()}
+ onKeyDown={(event) => event.stopPropagation()}
+ onClick={(event) => {
+ event.stopPropagation();
+ props.onOnly();
+ }}
+ >
+ {props.onlyLabel ?? 'Only'}
+ </Button>
+ </>
+ );
+}
diff --git a/apps/web/src/components/ui/index.ts b/apps/web/src/components/ui/index.ts
index c07d47a8ed..8d8aa75f9e 100644
--- a/apps/web/src/components/ui/index.ts
+++ b/apps/web/src/components/ui/index.ts
@@ -80,6 +80,7 @@ export type { DeleteDialogProps } from './components/DeleteDialog';
export { DeleteDialog } from './components/DeleteDialog';
export type { DialogProps } from './components/Dialog';
export { Dialog } from './components/Dialog';
+export type { DropdownMultiSelectItemProps } from './components/Dropdown';
export { Dropdown } from './components/Dropdown';
export type {
EmptyStateAction,
diff --git a/apps/web/src/components/ui/utils/multiSelectSelection.ts b/apps/web/src/components/ui/utils/multiSelectSelection.ts
new file mode 100644
index 0000000000..b1beb75033
--- /dev/null
+++ b/apps/web/src/components/ui/utils/multiSelectSelection.ts
@@ -0,0 +1,43 @@
+import { createSignal, onCleanup } from 'solid-js';
+
+export type MultiSelectIntent = 'add' | 'toggle' | 'only';
+
+/** Capture selection intent before Kobalte handles a row or search input. */
+export function createMultiSelectIntent() {
+ const [intent, setIntent] = createSignal<MultiSelectIntent>('add');
+ const track = (element: HTMLElement) => {
+ const capture = (event: MouseEvent | KeyboardEvent) => {
+ const checkbox =
+ event.target instanceof Element &&
+ event.target.closest('[data-multiselect-checkbox]');
+ if (checkbox) setIntent('toggle');
+ else if (event.shiftKey) setIntent('only');
+ else if (event instanceof KeyboardEvent && event.key === ' ')
+ setIntent('toggle');
+ else setIntent('add');
+ };
+ element.addEventListener('pointerdown', capture, true);
+ element.addEventListener('pointerup', capture, true);
+ element.addEventListener('click', capture, true);
+ element.addEventListener('keydown', capture, true);
+ onCleanup(() => {
+ element.removeEventListener('pointerdown', capture, true);
+ element.removeEventListener('pointerup', capture, true);
+ element.removeEventListener('click', capture, true);
+ element.removeEventListener('keydown', capture, true);
+ });
+ };
+ return { track, intent, shouldClose: () => intent() === 'add' };
+}
+
+/** Preserve other selections on row activation; Only replaces the selection. */
+export function applyMultiSelectSelection(
+ current: string[],
+ id: string,
+ intent: MultiSelectIntent
+): string[] {
+ if (intent === 'only') return [id];
+ if (intent === 'toggle' && current.includes(id))
+ return current.filter((value) => value !== id);
+ return current.includes(id) ? current : [...current, id];
+}
diff --git a/apps/web/src/components/view-shell/ListDropdowns.test.tsx b/apps/web/src/components/view-shell/ListDropdowns.test.tsx
index a5a1f19506..9e8afd13e4 100644
--- a/apps/web/src/components/view-shell/ListDropdowns.test.tsx
+++ b/apps/web/src/components/view-shell/ListDropdowns.test.tsx
@@ -55,11 +55,11 @@ afterEach(() => {
vi.unstubAllGlobals();
});
-function setup(single = false, searchable = false) {
- const [selected, setSelected] = createSignal<string[]>([]);
+function setup(single = false, searchable = false, initial: string[] = []) {
+ const [selected, setSelected] = createSignal<string[]>(initial);
const [open, setOpen] = createSignal(true);
render(() => (
- <ListFilterDropdown
+ <ListFilterDropdown<'people' | 'scope', string>
label="Filter tasks"
activeCount={selected().length}
open={open()}
@@ -74,6 +74,7 @@ function setup(single = false, searchable = false) {
{ id: 'alice', label: 'Alice' },
{ id: 'bob', label: 'Bob' },
{ id: 'carol', label: 'Carol' },
+ { id: 'disabled', label: 'Disabled', disabled: true },
],
},
{
@@ -84,6 +85,7 @@ function setup(single = false, searchable = false) {
},
]}
isSelected={(_, id) => selected().includes(id)}
+ selectedIds={(group) => (group === 'people' ? selected() : [])}
onSelectionChange={(_, id, checked) =>
setSelected((ids) =>
checked
@@ -120,48 +122,61 @@ async function openSubmenu() {
fireEvent.keyDown(trigger, { key: 'ArrowRight' });
}
-it('keeps multi-select menus open with Shift while adding and removing filters', async () => {
+it('toggles checkboxes without closing a multiselect submenu', async () => {
const { selected, open } = setup();
- const trigger = screen.getByLabelText('Filter tasks');
await openSubmenu();
+ const alice = await screen.findByRole('menuitemcheckbox', { name: 'Alice' });
selectOption(
- await screen.findByRole('menuitemcheckbox', { name: 'Alice' }),
- true
+ alice.querySelector<HTMLElement>('[data-multiselect-checkbox]')!
);
expect(selected()).toEqual(['alice']);
- expect(trigger.textContent).toBe('1');
expect(open()).toBe(true);
- expect(
- screen
- .getByRole('menuitemcheckbox', { name: 'Alice' })
- .getAttribute('aria-checked')
- ).toBe('true');
- selectOption(screen.getByRole('menuitemcheckbox', { name: 'Bob' }), true);
+ const bob = screen.getByRole('menuitemcheckbox', { name: 'Bob' });
+ selectOption(bob.querySelector<HTMLElement>('[data-multiselect-checkbox]')!);
expect(selected()).toEqual(['alice', 'bob']);
- expect(trigger.textContent).toBe('2');
- selectOption(screen.getByRole('menuitemcheckbox', { name: 'Alice' }), true);
+ selectOption(
+ alice.querySelector<HTMLElement>('[data-multiselect-checkbox]')!
+ );
expect(selected()).toEqual(['bob']);
- expect(trigger.textContent).toBe('1');
expect(open()).toBe(true);
+ expect(screen.getByLabelText('Filter tasks').textContent).toBe('1');
});
-it.each(['pointer', 'keyboard'])(
- 'closes multi-select menus after releasing Shift (%s)',
+it.each(['Alice', 'Bob'])(
+ 'adds a row without removing existing selections and closes (%s)',
+ async (name) => {
+ const { selected, open } = setup(false, false, ['alice']);
+ await openSubmenu();
+ selectOption(await screen.findByRole('menuitemcheckbox', { name }));
+ expect(selected()).toEqual(name === 'Alice' ? ['alice'] : ['alice', 'bob']);
+ await waitFor(() => expect(open()).toBe(false));
+ }
+);
+
+it.each(['pointer', 'keyboard', 'Only'])(
+ 'selects only one option and stays open (%s)',
async (input) => {
- const { selected, open } = setup();
+ const { selected, open } = setup(false, false, ['alice', 'carol']);
await openSubmenu();
- const alice = await screen.findByRole('menuitemcheckbox', {
- name: 'Alice',
+ const bob = await screen.findByRole('menuitemcheckbox', { name: 'Bob' });
+ if (input === 'pointer') selectOption(bob, true);
+ else if (input === 'keyboard')
+ fireEvent.keyDown(bob, { key: 'Enter', shiftKey: true });
+ else
+ fireEvent.click(screen.getByRole('button', { name: 'Select only Bob' }));
+ expect(selected()).toEqual(['bob']);
+ expect(open()).toBe(true);
+ fireEvent.click(screen.getByRole('button', { name: 'Select only Bob' }));
+ expect(selected()).toEqual(['bob']);
+ expect(open()).toBe(true);
+ fireEvent.keyDown(screen.getByRole('menuitemcheckbox', { name: 'Alice' }), {
+ key: ' ',
});
- if (input === 'pointer') selectOption(alice, true);
- else fireEvent.keyDown(alice, { key: 'Enter', shiftKey: true });
- await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(selected()).toEqual(['bob', 'alice']);
expect(open()).toBe(true);
- expect(selected()).toEqual(['alice']);
- if (input === 'pointer') selectOption(alice);
- else fireEvent.keyDown(alice, { key: 'Enter' });
+ fireEvent.keyDown(bob, { key: 'Enter' });
await waitFor(() => expect(open()).toBe(false));
- expect(selected()).toEqual([]);
+ expect(selected()).toEqual(['bob', 'alice']);
}
);
@@ -178,21 +193,190 @@ function clickSearchOption(element: HTMLElement, shiftKey: boolean) {
}
}
-it('Shift-click toggles individual searchable options without selecting a range', async () => {
+it('searchable checkboxes toggle while Shift-click and Only replace the selection without closing', async () => {
const { selected, open } = setup(false, true);
await openSubmenu();
const alice = await screen.findByRole('option', { name: 'Alice' });
- clickSearchOption(alice, true);
+ clickSearchOption(
+ alice.querySelector<HTMLElement>('[data-multiselect-checkbox]')!,
+ false
+ );
await waitFor(() => expect(selected()).toEqual(['alice']));
- clickSearchOption(screen.getByRole('option', { name: 'Carol' }), true);
+ clickSearchOption(
+ screen
+ .getByRole('option', { name: 'Carol' })
+ .querySelector<HTMLElement>('[data-multiselect-checkbox]')!,
+ false
+ );
await waitFor(() => expect(selected()).toEqual(['alice', 'carol']));
expect(open()).toBe(true);
clickSearchOption(screen.getByRole('option', { name: 'Alice' }), true);
- await waitFor(() => expect(selected()).toEqual(['carol']));
+ await waitFor(() => expect(selected()).toEqual(['alice']));
+ expect(open()).toBe(true);
+ fireEvent.click(screen.getByRole('button', { name: 'Select only Carol' }));
+ expect(selected()).toEqual(['carol']);
expect(open()).toBe(true);
clickSearchOption(screen.getByRole('option', { name: 'Carol' }), false);
await waitFor(() => expect(open()).toBe(false));
- expect(selected()).toEqual([]);
+ expect(selected()).toEqual(['carol']);
+});
+
+it.each([false, true])(
+ 'Only leaves other groups unchanged (searchable: %s)',
+ async (searchable) => {
+ const [people, setPeople] = createSignal(['alice', 'bob']);
+ const [status, setStatus] = createSignal(['open']);
+ render(() => (
+ <ListFilterDropdown
+ open
+ groups={[
+ {
+ id: 'people',
+ label: 'Assignee',
+ searchPlaceholder: searchable ? 'Search assignees...' : undefined,
+ options: [
+ { id: 'alice', label: 'Alice' },
+ { id: 'bob', label: 'Bob' },
+ ],
+ },
+ {
+ id: 'status',
+ label: 'Status',
+ options: [{ id: 'open', label: 'Open' }],
+ },
+ ]}
+ isSelected={(group, id) =>
+ (group === 'people' ? people() : status()).includes(id)
+ }
+ onSelectionChange={(group, id, checked) => {
+ const update = (ids: string[]) =>
+ checked ? [...ids, id] : ids.filter((value) => value !== id);
+ if (group === 'people') setPeople(update);
+ else setStatus(update);
+ }}
+ />
+ ));
+ await openSubmenu();
+ fireEvent.click(
+ await screen.findByRole('button', { name: 'Select only Bob' })
+ );
+ expect(people()).toEqual(['bob']);
+ expect(status()).toEqual(['open']);
+ }
+);
+
+it.each([
+ { searchable: false, disabledSelected: false },
+ { searchable: true, disabledSelected: false },
+ { searchable: false, disabledSelected: true },
+ { searchable: true, disabledSelected: true },
+])(
+ 'replaces the whole group in one write when persistence is deferred (searchable: $searchable, disabled selected: $disabledSelected)',
+ async ({ searchable, disabledSelected }) => {
+ const initial: Record<'people' | 'scope', string[]> = {
+ people: ['alice', 'carol', 'unavailable'],
+ scope: ['all'],
+ };
+ if (disabledSelected) initial.people.push('disabled');
+ const expectedPeople = disabledSelected ? ['disabled', 'bob'] : ['bob'];
+ const [filters, setFilters] = createSignal(initial);
+ const [open, setOpen] = createSignal(true);
+ let pending = initial;
+ const persist = vi.fn((next: typeof initial) => {
+ pending = next;
+ });
+ render(() => (
+ <ListFilterDropdown<'people' | 'scope', string>
+ open={open()}
+ onOpenChange={setOpen}
+ groups={[
+ {
+ id: 'people',
+ label: 'Assignee',
+ searchPlaceholder: searchable ? 'Search assignees...' : undefined,
+ options: [
+ { id: 'alice', label: 'Alice' },
+ { id: 'bob', label: 'Bob' },
+ { id: 'carol', label: 'Carol' },
+ { id: 'disabled', label: 'Disabled', disabled: true },
+ ],
+ },
+ {
+ id: 'scope',
+ label: 'Files',
+ options: [{ id: 'all', label: 'All files' }],
+ },
+ ]}
+ isSelected={(group, id) => filters()[group].includes(id)}
+ selectedIds={(group) => filters()[group]}
+ onSelectionChange={(group, id, selected) => {
+ const current = filters();
+ persist({
+ ...current,
+ [group]: selected
+ ? [...current[group], id]
+ : current[group].filter((value) => value !== id),
+ });
+ }}
+ onGroupSelectionChange={(group, ids) =>
+ persist({ ...filters(), [group]: [...ids] })
+ }
+ />
+ ));
+ await openSubmenu();
+ fireEvent.click(
+ await screen.findByRole('button', { name: 'Select only Bob' })
+ );
+
+ // Like Lexical settings, the committed filters stay stale until the write settles.
+ expect(filters()).toEqual(initial);
+ expect(persist).toHaveBeenCalledExactlyOnceWith({
+ people: expectedPeople,
+ scope: ['all'],
+ });
+ setFilters(pending);
+ expect(filters().people).toEqual(expectedPeople);
+ expect(filters().scope).toEqual(['all']);
+ expect(open()).toBe(true);
+ expect(
+ screen
+ .getByRole(searchable ? 'option' : 'menuitemcheckbox', { name: 'Bob' })
+ .getAttribute(searchable ? 'aria-selected' : 'aria-checked')
+ ).toBe('true');
+ fireEvent.click(screen.getByRole('button', { name: 'Select only Bob' }));
+ expect(persist).toHaveBeenCalledTimes(1);
+ }
+);
+
+it.each([false, true])(
+ 'disabled options cannot change selection (searchable: %s)',
+ async (searchable) => {
+ const { selected, open } = setup(false, searchable, ['alice']);
+ await openSubmenu();
+ const option = await screen.findByRole(
+ searchable ? 'option' : 'menuitemcheckbox',
+ { name: 'Disabled' }
+ );
+ if (searchable) clickSearchOption(option, true);
+ else selectOption(option, true);
+ fireEvent.click(
+ screen.getByRole('button', { name: 'Select only Disabled' })
+ );
+ expect(selected()).toEqual(['alice']);
+ expect(open()).toBe(true);
+ }
+);
+
+it('Shift-clicking a searchable checkbox still toggles only that checkbox', async () => {
+ const { selected, open } = setup(false, true, ['alice']);
+ await openSubmenu();
+ const carol = await screen.findByRole('option', { name: 'Carol' });
+ clickSearchOption(
+ carol.querySelector<HTMLElement>('[data-multiselect-checkbox]')!,
+ true
+ );
+ expect(selected()).toEqual(['alice', 'carol']);
+ expect(open()).toBe(true);
});
it('Enter closes the entire searchable filter menu after applying the selection', async () => {
@@ -208,7 +392,7 @@ it('Enter closes the entire searchable filter menu after applying the selection'
});
it.each(['pointer', 'keyboard'])(
- 'standalone searchable filters keep Shift selections open and close on a normal selection (%s)',
+ 'standalone searchable filters keep exclusive selection open and add on ordinary selection (%s)',
async (method) => {
const [selected, setSelected] = createSignal<string[]>([]);
const [open, setOpen] = createSignal(true);
@@ -246,10 +430,90 @@ it.each(['pointer', 'keyboard'])(
} else
clickSearchOption(screen.getByRole('option', { name: 'Alice' }), false);
await waitFor(() => expect(open()).toBe(false));
- expect(selected()).toEqual([]);
+ expect(selected()).toEqual(['alice']);
+ }
+);
+
+it.each([false, true])(
+ 'Only clears hidden group selections without ordinary toggles dropping them (searchable: %s)',
+ async (searchable) => {
+ const { selected, open } = setup(false, searchable, [
+ 'alice',
+ 'unavailable',
+ ]);
+ await openSubmenu();
+ const bob = await screen.findByRole(
+ searchable ? 'option' : 'menuitemcheckbox',
+ { name: 'Bob' }
+ );
+ const checkbox = bob.querySelector<HTMLElement>(
+ '[data-multiselect-checkbox]'
+ )!;
+ if (searchable) clickSearchOption(checkbox, false);
+ else selectOption(checkbox);
+ expect(selected()).toEqual(['alice', 'unavailable', 'bob']);
+ fireEvent.click(screen.getByRole('button', { name: 'Select only Bob' }));
+ expect(selected()).toEqual(['bob']);
+ expect(open()).toBe(true);
}
);
+it('preserves selected IDs absent from the current searchable options until Only replaces the selection', async () => {
+ const [selected, setSelected] = createSignal(['alice', 'unavailable']);
+ render(() => (
+ <SearchableMultiSelect
+ options={() => [
+ { id: 'alice', label: 'Alice' },
+ { id: 'bob', label: 'Bob' },
+ ]}
+ activeIds={selected}
+ onChange={setSelected}
+ open={() => true}
+ >
+ <Combobox.Trigger>People</Combobox.Trigger>
+ </SearchableMultiSelect>
+ ));
+ const alice = await screen.findByRole('option', { name: 'Alice' });
+ clickSearchOption(
+ alice.querySelector<HTMLElement>('[data-multiselect-checkbox]')!,
+ false
+ );
+ expect(selected()).toEqual(['unavailable']);
+ const bob = screen.getByRole('option', { name: 'Bob' });
+ clickSearchOption(
+ bob.querySelector<HTMLElement>('[data-multiselect-checkbox]')!,
+ false
+ );
+ expect(selected()).toEqual(['unavailable', 'bob']);
+ fireEvent.click(screen.getByRole('button', { name: 'Select only Bob' }));
+ expect(selected()).toEqual(['bob']);
+});
+
+it('runs a searchable action once and closes without changing the selected options', async () => {
+ const [selected, setSelected] = createSignal(['alice']);
+ const [open, setOpen] = createSignal(true);
+ const onSelect = vi.fn();
+ render(() => (
+ <SearchableMultiSelect
+ options={() => [{ id: 'alice', label: 'Alice' }]}
+ activeIds={selected}
+ onChange={setSelected}
+ open={open}
+ onOpenChange={setOpen}
+ action={{ label: 'Connect account', onSelect }}
+ >
+ <Combobox.Trigger>People</Combobox.Trigger>
+ </SearchableMultiSelect>
+ ));
+ clickSearchOption(
+ await screen.findByRole('option', { name: 'Connect account' }),
+ true
+ );
+ expect(onSelect).toHaveBeenCalledOnce();
+ expect(open()).toBe(false);
+ expect(selected()).toEqual(['alice']);
+});
+
it('shared checkbox filters support Shift+Enter and close after ordinary Enter', async () => {
const [checked, setChecked] = createSignal(false);
const [open, setOpen] = createSignal(true);
@@ -500,7 +764,7 @@ it('focuses searchable submenus on opening and reopening and supports keyboard s
fireEvent.keyDown(input, { key: 'ArrowDown' });
fireEvent.keyDown(input, { key: 'Enter', shiftKey: true });
await waitFor(() =>
- expect(selected()).toEqual(attempt ? ['alice', 'bob'] : ['alice'])
+ expect(selected()).toEqual(attempt ? ['bob'] : ['alice'])
);
expect(open()).toBe(true);
fireEvent.keyDown(input, { key: 'Escape' });
diff --git a/apps/web/src/components/view-shell/ListDropdowns.tsx b/apps/web/src/components/view-shell/ListDropdowns.tsx
index 948143a1e1..d19ed993a9 100644
--- a/apps/web/src/components/view-shell/ListDropdowns.tsx
+++ b/apps/web/src/components/view-shell/ListDropdowns.tsx
@@ -191,12 +191,19 @@ export type ListFilterDropdownProps<
> = {
groups: ListFilterGroup<TGroupId, TOptionId>[];
isSelected: (groupId: TGroupId, optionId: TOptionId) => boolean;
+ /** Include persisted selections absent from dynamic options, such as removed contacts. */
+ selectedIds?: (groupId: TGroupId) => readonly TOptionId[];
isGroupActive?: (groupId: TGroupId) => boolean;
onSelectionChange: (
groupId: TGroupId,
optionId: TOptionId,
selected: boolean
) => void;
+ /** Replace a group's selection in one write for deferred persistence. */
+ onGroupSelectionChange?: (
+ groupId: TGroupId,
+ ids: readonly TOptionId[]
+ ) => void;
onClear?: () => void;
/**
* Adds a plain-English box above the groups that resolves a description
@@ -248,6 +255,45 @@ export function ListFilterDropdown<
props.isSelected(group.id, option.id)
);
+ const selectedOptionIds = (group: ListFilterGroup<TGroupId, TOptionId>) => [
+ ...new Set([
+ ...(props.selectedIds?.(group.id) ?? []),
+ ...group.options
+ .filter((option) => props.isSelected(group.id, option.id))
+ .map((option) => option.id),
+ ]),
+ ];
+ const setSelectedOptionIds = (
+ group: ListFilterGroup<TGroupId, TOptionId>,
+ ids: readonly string[]
+ ) => {
+ const current = selectedOptionIds(group);
+ const optionIds = [
+ ...new Set([...current, ...group.options.map((option) => option.id)]),
+ ];
+ const next = optionIds.filter((id) => {
+ if (group.options.find((option) => option.id === id)?.disabled)
+ return current.includes(id);
+ return ids.includes(id);
+ });
+ if (
+ next.length === current.length &&
+ next.every((id) => current.includes(id))
+ )
+ return;
+ if (props.onGroupSelectionChange) {
+ props.onGroupSelectionChange(group.id, next);
+ return;
+ }
+ batch(() => {
+ for (const id of optionIds) {
+ const selected = next.includes(id);
+ if (selected !== current.includes(id))
+ props.onSelectionChange(group.id, id, selected);
+ }
+ });
+ };
+
return (
<Dropdown open={isOpen()} onOpenChange={setOpen} placement="bottom-end">
<Show
@@ -329,9 +375,8 @@ export function ListFilterDropdown<
!props.isSelected(group().id, id)
)
}
- closeOnSelect={
- group().selectionMode === 'single' ? true : 'unless-shift'
- }
+ onOnly={(id) => setSelectedOptionIds(group(), [id])}
+ closeOnSelect
contentClass={group().contentClass}
/>
}
@@ -341,29 +386,8 @@ export function ListFilterDropdown<
label={group().label}
active={isGroupActive(group())}
options={() => group().options}
- activeIds={() =>
- group()
- .options.filter((option) =>
- props.isSelected(group().id, option.id)
- )
- .map((option) => option.id)
- }
- onChange={(ids) =>
- batch(() => {
- for (const option of group().options) {
- const selected = ids.includes(option.id);
- if (
- selected !== props.isSelected(group().id, option.id)
- ) {
- props.onSelectionChange(
- group().id,
- option.id,
- selected
- );
- }
- }
- })
- }
+ activeIds={() => selectedOptionIds(group())}
+ onChange={(ids) => setSelectedOptionIds(group(), ids)}
placeholder={group().searchPlaceholder}
/>
</Show>
diff --git a/apps/web/src/features/agents-view/components/ConversationListControls.tsx b/apps/web/src/features/agents-view/components/ConversationListControls.tsx
index 0ccb6db4db..c9666b4655 100644
--- a/apps/web/src/features/agents-view/components/ConversationListControls.tsx
+++ b/apps/web/src/features/agents-view/components/ConversationListControls.tsx
@@ -127,6 +127,7 @@ export function ConversationListControls(props: ConversationListControlsProps) {
class="size-(--sidebar-control-size)"
groups={FILTER_GROUPS}
isSelected={isSelected}
+ selectedIds={(group) => props.filters[group]}
onSelectionChange={props.onFilterChange}
onClear={props.onClearFilters}
/>
diff --git a/apps/web/src/features/drive-view/filters/use-drive-filters.test.tsx b/apps/web/src/features/drive-view/filters/use-drive-filters.test.tsx
index 6da5944d81..7d67286ae2 100644
--- a/apps/web/src/features/drive-view/filters/use-drive-filters.test.tsx
+++ b/apps/web/src/features/drive-view/filters/use-drive-filters.test.tsx
@@ -60,7 +60,7 @@ afterEach(() => {
});
it.each(['pointer', 'keyboard'])(
- 'keeps the Drive Type submenu mounted while Shift-selecting and deselecting file types (%s)',
+ 'keeps the Drive Type submenu mounted while toggling file types, then adds and closes (%s)',
async (input) => {
const [value, setValue] = createSignal<DriveState>({
location: { kind: 'tab', tab: 'owned' },
@@ -104,14 +104,13 @@ it.each(['pointer', 'keyboard'])(
const select = (element: HTMLElement) => {
if (input === 'keyboard') {
element.focus();
- fireEvent.keyDown(element, { key: 'Enter', shiftKey: true });
+ fireEvent.keyDown(element, { key: ' ' });
} else
fireEvent(
- element,
+ element.querySelector<HTMLElement>('[data-multiselect-checkbox]')!,
new MouseEvent('pointerup', {
button: 0,
bubbles: true,
- shiftKey: true,
})
);
};
@@ -131,6 +130,6 @@ it.each(['pointer', 'keyboard'])(
pdf.focus();
fireEvent.keyDown(pdf, { key: 'Enter' });
await waitFor(() => expect(pdf.isConnected).toBe(false));
- expect(value().facets.type).toBeUndefined();
+ expect(value().facets.type).toEqual(['file-pdf']);
}
);
diff --git a/apps/web/src/features/drive-view/filters/use-drive-filters.tsx b/apps/web/src/features/drive-view/filters/use-drive-filters.tsx
index 86067072ff..f9892f2388 100644
--- a/apps/web/src/features/drive-view/filters/use-drive-filters.tsx
+++ b/apps/web/src/features/drive-view/filters/use-drive-filters.tsx
@@ -181,6 +181,10 @@ export function useDriveFilters() {
return {
groups,
isSelected,
+ selectedIds: (group: DriveFilterGroupId) =>
+ group === 'scope'
+ ? [state.value().scope]
+ : (state.value().facets[group] ?? []),
setSelected,
activeCount,
clear: state.clearFilters,
diff --git a/apps/web/src/features/drive-view/views/drive-filter-menu.tsx b/apps/web/src/features/drive-view/views/drive-filter-menu.tsx
index fdf68a7811..4f9f65945f 100644
--- a/apps/web/src/features/drive-view/views/drive-filter-menu.tsx
+++ b/apps/web/src/features/drive-view/views/drive-filter-menu.tsx
@@ -37,6 +37,7 @@ export function DriveFilterMenu() {
groups={filters.groups()}
onClear={filters.clear}
isSelected={filters.isSelected}
+ selectedIds={filters.selectedIds}
onSelectionChange={filters.setSelected}
/>
<ListFilterCountBadge count={filters.activeCount()} />
diff --git a/apps/web/src/features/email-view/components/EmailControls.tsx b/apps/web/src/features/email-view/components/EmailControls.tsx
index 86daba7140..4be609213d 100644
--- a/apps/web/src/features/email-view/components/EmailControls.tsx
+++ b/apps/web/src/features/email-view/components/EmailControls.tsx
@@ -31,6 +31,7 @@ export function EmailControls(props: EmailControlsProps) {
onOpenChange={props.onFilterOpenChange}
groups={filters.groups()}
isSelected={filters.isSelected}
+ selectedIds={filters.selectedIds}
onSelectionChange={filters.setSelected}
onClear={filters.clear}
/>
diff --git a/apps/web/src/features/email-view/filters/use-email-filters.tsx b/apps/web/src/features/email-view/filters/use-email-filters.tsx
index 25cfcf1d8e..be1ddf6f57 100644
--- a/apps/web/src/features/email-view/filters/use-email-filters.tsx
+++ b/apps/web/src/features/email-view/filters/use-email-filters.tsx
@@ -69,7 +69,7 @@ export function useEmailFilters() {
return;
}
- // Persisted facets preserve unknown IDs; menu actions only accept known IDs.
+ // Preserve unknown IDs during toggles; Only explicitly removes other IDs.
const update = selected
? addUnique<string>(optionId)
: removeValue<string>(optionId);
@@ -83,6 +83,7 @@ export function useEmailFilters() {
groups,
activeCount: activeFilterCount,
isSelected,
+ selectedIds: (groupId: EmailFilterGroupId) => state.facets[groupId] ?? [],
setSelected,
clear: () => setFacets({}),
};
diff --git a/apps/web/src/features/home/components/HomeFilters.tsx b/apps/web/src/features/home/components/HomeFilters.tsx
index e03ee565f3..5b243565de 100644
--- a/apps/web/src/features/home/components/HomeFilters.tsx
+++ b/apps/web/src/features/home/components/HomeFilters.tsx
@@ -167,6 +167,7 @@ function useHomeFilters() {
TYPE_IDS.length
: (state.facets[groupId]?.length ?? 0) > 0,
isSelected,
+ selectedIds: (groupId: string) => state.facets[groupId] ?? [],
setSelected,
};
}
@@ -230,6 +231,7 @@ export function HomeFilterDropdown() {
open={open()}
onOpenChange={setOpen}
isSelected={filters.isSelected}
+ selectedIds={filters.selectedIds}
isGroupActive={filters.isGroupActive}
onSelectionChange={filters.setSelected}
onClear={filters.clear}
diff --git a/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx b/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx
index 5de24deea3..4a8dc31060 100644
--- a/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx
+++ b/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx
@@ -208,16 +208,10 @@ export function FilterOptionItem(props: {
disabled?: boolean;
closeOnSelect?: SelectionDismissal;
onSelect: () => void;
+ onOnly?: () => void;
}) {
- return (
- <Dropdown.Item
- role="menuitemcheckbox"
- aria-checked={props.active}
- disabled={props.disabled}
- onSelect={props.onSelect}
- closeOnSelect={props.closeOnSelect}
- >
- <TypeIndicator active={props.active} />
+ const content = () => (
+ <>
<Show when={props.icon}>
{(icon) => (
<span class="size-4 flex items-center justify-center shrink-0">
@@ -233,7 +227,38 @@ export function FilterOptionItem(props: {
>
{props.content?.() ?? props.label}
</span>
- </Dropdown.Item>
+ </>
+ );
+ return (
+ <Show
+ when={props.onOnly}
+ fallback={
+ <Dropdown.Item
+ role="menuitemcheckbox"
+ aria-checked={props.active}
+ disabled={props.disabled}
+ onSelect={props.onSelect}
+ closeOnSelect={props.closeOnSelect}
+ >
+ <TypeIndicator active={props.active} />
+ {content()}
+ </Dropdown.Item>
+ }
+ >
+ {(onOnly) => (
+ <Dropdown.MultiSelectItem
+ checked={props.active}
+ label={props.label}
+ disabled={props.disabled}
+ onChange={(checked) => {
+ if (checked !== props.active) props.onSelect();
+ }}
+ onOnly={onOnly()}
+ >
+ {content()}
+ </Dropdown.MultiSelectItem>
+ )}
+ </Show>
);
}
@@ -265,6 +290,7 @@ export function FilterSubmenu<TId extends string>(props: {
isSelected: (id: TId) => boolean;
onSelect: (id: TId) => void;
closeOnSelect?: SelectionDismissal;
+ onOnly?: (id: TId) => void;
contentClass?: string;
selectionMode?: 'single' | 'multiple';
}) {
@@ -297,6 +323,7 @@ export function FilterSubmenu<TId extends string>(props: {
disabled={option().disabled}
active={props.isSelected(option().id)}
onSelect={() => props.onSelect(option().id)}
+ onOnly={props.onOnly && (() => props.onOnly?.(option().id))}
closeOnSelect={props.closeOnSelect}
/>
)}
diff --git a/apps/web/src/features/next-soup/soup-view/filters-bar/searchable-multi-select.tsx b/apps/web/src/features/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
index bbd6da3de8..d2ccb6fc66 100644
--- a/apps/web/src/features/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
+++ b/apps/web/src/features/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
@@ -1,11 +1,14 @@
import { useSelectedFirst } from '@core/util/useSelectedFirst';
import type { CollectionNode } from '@kobalte/core';
import { Combobox, useComboboxContext } from '@kobalte/core/combobox';
-import CheckIcon from '@phosphor/check.svg';
import SearchIcon from '@phosphor/magnifying-glass.svg';
import { makeEventListener } from '@solid-primitives/event-listener';
import { cn, Layer } from '@ui';
-import { createSelectionDismissal } from '@ui/utils/selectionDismissal';
+import { MultiSelectItemContent } from '@ui/components/MultiSelectItemContent';
+import {
+ applyMultiSelectSelection,
+ createMultiSelectIntent,
+} from '@ui/utils/multiSelectSelection';
import {
type Accessor,
createMemo,
@@ -21,6 +24,7 @@ export type SearchableOption = {
icon?: () => JSX.Element;
/** Drawn in place of `label`, which still drives search. */
content?: () => JSX.Element;
+ disabled?: boolean;
};
export type SearchableSelectAction = {
@@ -57,11 +61,7 @@ type SearchableMultiSelectProps = {
listboxClass?: string;
/** Keep `options` in their given order instead of pinning selected first. */
preserveOrder?: boolean;
- /**
- * Render a per-row "Only" action that narrows the selection to that row.
- * When the row is already the sole active one the label flips to "All" and
- * the handler is expected to restore the full selection.
- */
+ /** Optional Only/All behavior for tri-state filters such as inboxes. */
onOnly?: (id: string) => void;
/** Non-toggling action row appended after the options. */
action?: SearchableSelectAction;
@@ -74,6 +74,7 @@ const SearchableMultiSelectItem = (itemProps: {
item: CollectionNode<SearchableOption>;
onOnly?: (id: string) => void;
isSoleActive?: (id: string) => boolean;
+ selectionIntent: ReturnType<typeof createMultiSelectIntent>;
}) => {
const combobox = useComboboxContext();
let selectedOnPointerUp = false;
@@ -83,8 +84,9 @@ const SearchableMultiSelectItem = (itemProps: {
<Combobox.Item
item={itemProps.item}
ref={(element) => {
- // Kobalte composes item handlers without checking defaultPrevented.
- // Intercept Shift selection before those handlers can select a range.
+ itemProps.selectionIntent.track(element);
+ // Intercept Shift activation before Kobalte selects a range. The change
+ // handler turns the resulting single-item toggle into exclusive selection.
const intercept = (event: Event) => {
event.preventDefault();
event.stopImmediatePropagation();
@@ -143,57 +145,56 @@ const SearchableMultiSelectItem = (itemProps: {
true
);
}}
- class="group rounded-lg w-full flex items-center gap-1.5 p-1.5 px-2 text-left text-sm font-normal data-highlighted:bg-ink/5 cursor-default"
+ aria-label={itemProps.item.rawValue.label}
+ aria-keyshortcuts="Space Enter Shift+Enter"
+ class={cn(
+ 'group relative rounded-lg w-full flex items-center gap-1.5 p-1.5 px-2 text-left text-sm font-normal data-highlighted:bg-ink/5 cursor-default touch:min-h-11',
+ itemProps.item.rawValue.id !== ACTION_ID && 'pr-14'
+ )}
>
- <Show when={itemProps.item.rawValue.id !== ACTION_ID}>
- <span
- class={cn(
- 'size-3.5 flex items-center justify-center shrink-0 rounded-sm border text-surface',
- 'border-transparent group-hover:not-hover:border-edge-muted group-data-highlighted:not-hover:border-edge-muted hover:border-accent',
- 'group-data-selected:bg-accent group-data-selected:border-accent'
- )}
- >
- <Combobox.ItemIndicator>
- <CheckIcon class="size-2.5" />
- </Combobox.ItemIndicator>
- </span>
- </Show>
- <Show when={itemProps.item.rawValue.icon}>
- {(icon) => (
- <span class="size-4 flex items-center justify-center shrink-0">
- {icon()()}
- </span>
- )}
- </Show>
- <Combobox.ItemLabel class="flex-1 truncate text-ink">
- {itemProps.item.rawValue.content?.() ?? itemProps.item.rawValue.label}
- </Combobox.ItemLabel>
<Show
- when={
- itemProps.item.rawValue.id !== ACTION_ID
- ? itemProps.onOnly
- : undefined
+ when={itemProps.item.rawValue.id !== ACTION_ID}
+ fallback={
+ <>
+ <Show when={itemProps.item.rawValue.icon}>
+ {(icon) => (
+ <span class="size-4 flex items-center justify-center shrink-0">
+ {icon()()}
+ </span>
+ )}
+ </Show>
+ <Combobox.ItemLabel class="flex-1 truncate text-ink">
+ {itemProps.item.rawValue.label}
+ </Combobox.ItemLabel>
+ </>
}
>
- {(onOnly) => (
- <button
- type="button"
- class="shrink-0 text-xxs text-ink-muted opacity-0 group-hover:opacity-100 group-data-highlighted:opacity-100 hover:text-ink"
- onPointerDown={(e) => {
- e.preventDefault();
- e.stopPropagation();
- }}
- onPointerUp={(e) => e.stopPropagation()}
- onClick={(e) => {
- e.stopPropagation();
- onOnly()(itemProps.item.rawValue.id);
- }}
- >
- {itemProps.isSoleActive?.(itemProps.item.rawValue.id)
+ <MultiSelectItemContent
+ checked={combobox
+ .listState()
+ .selectionManager()
+ .isSelected(itemProps.item.key)}
+ label={itemProps.item.rawValue.label}
+ disabled={itemProps.item.rawValue.disabled}
+ onOnly={() => itemProps.onOnly?.(itemProps.item.rawValue.id)}
+ onlyLabel={
+ itemProps.isSoleActive?.(itemProps.item.rawValue.id)
? 'All'
- : 'Only'}
- </button>
- )}
+ : 'Only'
+ }
+ >
+ <Show when={itemProps.item.rawValue.icon}>
+ {(icon) => (
+ <span class="size-4 flex items-center justify-center shrink-0">
+ {icon()()}
+ </span>
+ )}
+ </Show>
+ <Combobox.ItemLabel class="flex-1 truncate text-ink">
+ {itemProps.item.rawValue.content?.() ??
+ itemProps.item.rawValue.label}
+ </Combobox.ItemLabel>
+ </MultiSelectItemContent>
</Show>
</Combobox.Item>
);
@@ -203,6 +204,7 @@ const VirtualizedListbox = (props: {
class?: string;
onOnly?: (id: string) => void;
isSoleActive?: (id: string) => boolean;
+ selectionIntent: ReturnType<typeof createMultiSelectIntent>;
}) => {
let handle: VirtualizerHandle | undefined;
// Kobalte supplies the collection after applying the combobox search
@@ -236,6 +238,7 @@ const VirtualizedListbox = (props: {
item={item}
onOnly={props.onOnly}
isSoleActive={props.isSoleActive}
+ selectionIntent={props.selectionIntent}
/>
)}
</Virtualizer>
@@ -278,7 +281,7 @@ const useActiveOptions = (
const getOptionId = (opt: SearchableOption) => opt.id;
export const SearchableMultiSelect = (props: SearchableMultiSelectProps) => {
- const selection = createSelectionDismissal();
+ const selectionIntent = createMultiSelectIntent();
const [internalOpen, setInternalOpen] = createSignal(false);
const [searchQuery, setSearchQuery] = createSignal('');
@@ -319,21 +322,34 @@ export const SearchableMultiSelect = (props: SearchableMultiSelectProps) => {
props.action.onSelect();
return;
}
- props.onChange(selected.map((o) => o.id));
+ const id =
+ selected.find((option) => !props.activeIds().includes(option.id))?.id ??
+ activeOptions().find(
+ (option) => !selected.some((next) => next.id === option.id)
+ )?.id;
+ if (id !== undefined)
+ props.onChange(
+ applyMultiSelectSelection(
+ props.activeIds(),
+ id,
+ selectionIntent.intent()
+ )
+ );
dismissAfterSelection();
};
const dismissAfterSelection = () => {
- if (selection.shouldClose()) queueMicrotask(() => handleOpenChange(false));
+ if (selectionIntent.shouldClose())
+ queueMicrotask(() => handleOpenChange(false));
};
const handleOnly = (id: string) => {
- props.onOnly?.(id);
- dismissAfterSelection();
+ if (props.onOnly) props.onOnly(id);
+ else props.onChange([id]);
};
const isSoleActive = (id: string) => {
const ids = props.activeIds();
- return ids.length === 1 && ids[0] === id;
+ return !!props.onOnly && ids.length === 1 && ids[0] === id;
};
return (
@@ -350,6 +366,7 @@ export const SearchableMultiSelect = (props: SearchableMultiSelectProps) => {
optionValue="id"
optionTextValue="label"
optionLabel="label"
+ optionDisabled="disabled"
allowsEmptyCollection
virtualized
removeOnBackspace={false}
@@ -358,13 +375,13 @@ export const SearchableMultiSelect = (props: SearchableMultiSelectProps) => {
>
<Combobox.Control class="flex items-center h-full">
{props.children}
- <Combobox.Input ref={selection.track} class="sr-only" />
+ <Combobox.Input ref={selectionIntent.track} class="sr-only" />
</Combobox.Control>
<Combobox.Portal>
<Layer depth={2}>
<Combobox.Content
- ref={selection.track}
+ ref={selectionIntent.track}
class={cn(
'menu-surface z-action-menu w-65 max-w-[90vw] overflow-hidden',
props.contentClass
@@ -390,8 +407,9 @@ export const SearchableMultiSelect = (props: SearchableMultiSelectProps) => {
>
<VirtualizedListbox
class={props.listboxClass}
- onOnly={props.onOnly && handleOnly}
+ onOnly={handleOnly}
isSoleActive={isSoleActive}
+ selectionIntent={selectionIntent}
/>
</Show>
</div>
@@ -424,7 +442,7 @@ type SearchableMultiSelectInlineProps = {
export const SearchableMultiSelectInline = (
props: SearchableMultiSelectInlineProps
) => {
- const selection = createSelectionDismissal();
+ const selectionIntent = createMultiSelectIntent();
const [searchQuery, setSearchQuery] = createSignal('');
const activeOptions = useActiveOptions(props.options, props.activeIds);
@@ -442,8 +460,20 @@ export const SearchableMultiSelectInline = (
props.preserveOrder ? props.options() : selectedFirstOptions();
const handleChange = (selected: SearchableOption[]) => {
- props.onChange(selected.map((o) => o.id));
- if (selection.shouldClose())
+ const id =
+ selected.find((option) => !props.activeIds().includes(option.id))?.id ??
+ activeOptions().find(
+ (option) => !selected.some((next) => next.id === option.id)
+ )?.id;
+ if (id !== undefined)
+ props.onChange(
+ applyMultiSelectSelection(
+ props.activeIds(),
+ id,
+ selectionIntent.intent()
+ )
+ );
+ if (selectionIntent.shouldClose())
queueMicrotask(() => props.onSelectionComplete?.());
};
@@ -492,12 +522,13 @@ export const SearchableMultiSelectInline = (
optionValue="id"
optionTextValue="label"
optionLabel="label"
+ optionDisabled="disabled"
allowsEmptyCollection
virtualized
removeOnBackspace={false}
>
<div
- ref={selection.track}
+ ref={selectionIntent.track}
class="flex items-center gap-2 px-3 py-2 border-b border-edge-muted"
>
<SearchIcon class="size-3.5 text-ink-muted shrink-0" />
@@ -508,7 +539,7 @@ export const SearchableMultiSelectInline = (
placeholder={props.placeholder ?? 'Search...'}
/>
</div>
- <div ref={selection.track} class="p-1">
+ <div ref={selectionIntent.track} class="p-1">
<Show
when={hasMatches()}
fallback={
@@ -517,7 +548,11 @@ export const SearchableMultiSelectInline = (
</div>
}
>
- <VirtualizedListbox class={props.listboxClass} />
+ <VirtualizedListbox
+ class={props.listboxClass}
+ selectionIntent={selectionIntent}
+ onOnly={(id) => props.onChange([id])}
+ />
</Show>
</div>
</Combobox>
diff --git a/apps/web/src/features/reviews-view/components/ReviewsControls.tsx b/apps/web/src/features/reviews-view/components/ReviewsControls.tsx
index d7feb8da6e..328dc90b4b 100644
--- a/apps/web/src/features/reviews-view/components/ReviewsControls.tsx
+++ b/apps/web/src/features/reviews-view/components/ReviewsControls.tsx
@@ -198,6 +198,7 @@ export function ReviewsControls(
onOpenChange={handleMenuOpenChange('filters')}
triggerRef={(element) => (filterTrigger = element)}
isSelected={(group, id) => isSelected(props, group, id)}
+ selectedIds={(group) => props.selected[group]}
onSelectionChange={props.onFilterChange}
onClear={props.onClearFilters}
/>
diff --git a/apps/web/src/features/tasks-view/components/TasksControls.tsx b/apps/web/src/features/tasks-view/components/TasksControls.tsx
index 4ee9817338..fa5123e181 100644
--- a/apps/web/src/features/tasks-view/components/TasksControls.tsx
+++ b/apps/web/src/features/tasks-view/components/TasksControls.tsx
@@ -93,6 +93,7 @@ function DesktopTasksControls() {
onOpenChange={handleMenuOpenChange('filters')}
triggerRef={(element) => (filterTrigger = element)}
isSelected={filters.isSelected}
+ selectedIds={filters.selectedIds}
onSelectionChange={filters.setSelected}
onClear={filters.clear}
aiFilter={{
diff --git a/apps/web/src/features/tasks-view/filters/use-task-filters.tsx b/apps/web/src/features/tasks-view/filters/use-task-filters.tsx
index 8329a11a0c..5ba3b08186 100644
--- a/apps/web/src/features/tasks-view/filters/use-task-filters.tsx
+++ b/apps/web/src/features/tasks-view/filters/use-task-filters.tsx
@@ -166,6 +166,7 @@ export function useTaskFilters() {
clear: () => setFacets({}),
groups,
isSelected,
+ selectedIds: (groupId: TaskFilterGroupId) => state.facets[groupId] ?? [],
setSelected,
};
}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/task-list/TaskListControls.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/task-list/TaskListControls.tsx
index edd4a74f36..f0b2e8212f 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/task-list/TaskListControls.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/task-list/TaskListControls.tsx
@@ -383,7 +383,13 @@ function TaskListBar(props: {
onOpenChange={setMenuOpen}
groups={filterGroups()}
isSelected={isSelected}
+ selectedIds={(group) => props.settings().filters[group]}
onSelectionChange={setFilterValue}
+ onGroupSelectionChange={(group, ids) =>
+ props.update({
+ filters: { ...props.settings().filters, [group]: [...ids] },
+ })
+ }
onClear={() =>
props.update({
filters: { status: [], priority: [], assignees: [], due: [] },
diff --git a/docs/agent-guide/assets/multiselect-dropdown-desktop.png b/docs/agent-guide/assets/multiselect-dropdown-desktop.png
new file mode 100644
index 0000000000..31871888eb
Binary files /dev/null and b/docs/agent-guide/assets/multiselect-dropdown-desktop.png differ
diff --git a/docs/agent-guide/assets/multiselect-dropdown-touch.png b/docs/agent-guide/assets/multiselect-dropdown-touch.png
new file mode 100644
index 0000000000..55e3e89da8
Binary files /dev/null and b/docs/agent-guide/assets/multiselect-dropdown-touch.png differ
diff --git a/docs/agent-guide/files.md b/docs/agent-guide/files.md
index b85abbb3e5..ee2ca6465b 100644
--- a/docs/agent-guide/files.md
+++ b/docs/agent-guide/files.md
@@ -135,10 +135,11 @@ attachments. Options within a group match any selected option; different groups
combine to narrow the results. Created by is hidden while My Files
is restricted to your own files. Recent offers only file-scope filtering.
The desktop Filter trigger shows the number of active filters, matching the
-mobile drawer; clearing all filters removes the badge. Hold Shift while selecting
-or deselecting Type options to keep the submenu open and combine several file
-types without reopening it. A normal selection closes the menu. Verify the badge
-tracks consecutive selections (1 → 2 → 1), including when filter groups refresh
+mobile drawer; clearing all filters removes the badge. Use the left checkboxes
+(or Space) to combine Type options without closing. Row activation adds and
+closes; Shift-click or **Only** selects just one type and stays open, following
+[shared multiselect behavior](ui-conventions.md#multiselect-dropdowns). Verify the badge
+tracks consecutive checkbox toggles (1 → 2 → 1), including when filter groups refresh
while the menu is open. Desktop filter submenus allow a
250 ms grace period when the mouse crosses the parent menu's padding; entering
the submenu cancels the pending close. While the mouse heads toward an open
diff --git a/docs/agent-guide/home.md b/docs/agent-guide/home.md
index d7852ead2a..7014593d2d 100644
--- a/docs/agent-guide/home.md
+++ b/docs/agent-guide/home.md
@@ -57,7 +57,9 @@ completing the channel leaves the thread.
The menu shares the legacy compact submenus: **Status** offers **Unread**, **Read**,
and **All** as single-select radio items with a checkmark on the right of the selected
option, and **Type** contains the entity checkboxes. Status closes the menu
-after selection; type selections leave it open. Press **f** to open the menu.
+after selection. Type uses the [shared multiselect dropdown pattern](ui-conventions.md#multiselect-dropdowns):
+checkboxes toggle without closing, rows add and close, and Shift/Only selects just
+one type without closing. Press **f** to open the menu.
Entity type checkboxes start checked. Unchecking **Email** hides received
and sent mail. **Channels** controls
both channels and reply threads; **Chats** and **Agents** have separate toggles.
diff --git a/docs/agent-guide/soup-live-updates.md b/docs/agent-guide/soup-live-updates.md
index ffa88abd81..270a387457 100644
--- a/docs/agent-guide/soup-live-updates.md
+++ b/docs/agent-guide/soup-live-updates.md
@@ -129,11 +129,11 @@ editing: only moved or removed rows should be added or removed. Rename a row and
then drag it: its drag label/payload must use the new fields without another
registration/layout measurement.
-Desktop multi-select filter menus in Home, Tasks, Drive, Email, Reviews, Search,
-CRM, Calendar, and database option-value filters close after an ordinary click or
-Enter. Hold Shift while clicking or pressing Enter to toggle individual options
-and keep the menu open for further selections. Shift does not select a range.
-Single-select controls and mobile filter drawers retain their existing behavior.
+Shared list-filter menus in Home, Tasks, Drive, Email, Reviews, and CRM, plus
+searchable filter dropdowns, use the [multiselect dropdown pattern](ui-conventions.md#multiselect-dropdowns):
+checkbox toggles stay open, row activation adds and closes, and Shift/Only
+replaces the current group's selection without closing. Single-select controls,
+independent settings, and mobile filter drawers retain their existing behavior.
Channels use the same general Soup reconciliation path, not a separate local page
chain. Channel ID, type, team, organization, importance, and participant-scoped
diff --git a/docs/agent-guide/tasks.md b/docs/agent-guide/tasks.md
index a1f29aa8b1..e5afe8c201 100644
--- a/docs/agent-guide/tasks.md
+++ b/docs/agent-guide/tasks.md
@@ -9,7 +9,9 @@ The single-row desktop header contains the title, `Filter`, a separate
(`Ctrl+F` opens it). The active-filter count sits beside the filter icon inside
its button, without overlapping the icon or the group border;
the filter uses the legacy compact option rows and searchable Assignee, Created by,
-and Tags submenus. Multi-select choices keep the menu open; Escape dismisses it.
+and Tags submenus. They use the [shared multiselect dropdown pattern](ui-conventions.md#multiselect-dropdowns):
+checkboxes toggle and stay open, rows add and close, and Shift/Only selects just
+one option and stays open. Escape dismisses the menu.
The top of the `Filter` menu is a `Filter with AI…` textbox, focused when the menu opens: type a plain-English
description such as `urgent and high priority tasks that are not completed` and press
Enter. It replaces the current selection with the matching Status, Priority, Assignee,
diff --git a/docs/agent-guide/ui-conventions.md b/docs/agent-guide/ui-conventions.md
index 935226238f..e71ccdcb35 100644
--- a/docs/agent-guide/ui-conventions.md
+++ b/docs/agent-guide/ui-conventions.md
@@ -90,6 +90,32 @@ at the top-right and bottom-left corners. Light themes keep a soft highlight
through those corners so they are only slightly dimmer. The iOS app also uses shared
[glass press feedback](navigation.md#mobile-glass-feedback).
+## Multiselect dropdowns
+
+Use `Dropdown.MultiSelectItem` for filter options, not independent settings.
+Clicking the left checkbox toggles only that option and keeps the menu open.
+Clicking the rest of the row adds the option and closes the whole dropdown;
+clicking an already-selected row leaves it selected. Shift-click or **Only**
+replaces that group's selection with the option and keeps the menu open, even
+when it is already the sole selection. Other filter groups stay unchanged.
+Only also clears persisted selections missing from the current options. Dynamic
+`ListFilterDropdown` callers supply `selectedIds` so hidden values remain known;
+ordinary checkbox and row actions preserve those values.
+Callers with deferred persistence supply `onGroupSelectionChange` to replace a
+whole group's selection in one write, without intermediate per-option writes.
+
+Arrow keys navigate. Space toggles a focused menu row; Enter adds and closes;
+Shift+Enter selects only that option without closing. Searchable filters retain
+input focus and use Enter/Shift+Enter on the highlighted search result.
+**Only** sits at the right on hover or keyboard highlight and remains visible on
+touch devices. Touch rows and checkbox hit areas use the shared touch sizing.
+Existing mobile filter drawers retain their toggle-and-stay-open behavior.
+Inbox selectors retain their explicit **Only**/**All** reset action.
+
+| Pointer dropdown | Touch dropdown |
+| --- | --- |
+| ![Only appears on the highlighted row](assets/multiselect-dropdown-desktop.png) | ![Only stays visible on touch rows](assets/multiselect-dropdown-touch.png) |
+
## Mobile filters
Adjacent checked options in a filter section share one continuous selection