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.

fix(properties): open a focused pill's editor on Enter (#9331)

gbirman0a4913ceb38d
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index e7fdb34706..e7bf2f1ffb 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -893,6 +893,15 @@ Use the shared scoped drag helpers and overlayIcon for the tag chip.
The backend-free browser regression is
`bunx playwright test --config src/features/property/tags/browser-test/playwright.config.ts`.
+### Enter on a property pill
+
+A document control owns Enter unless a press focused it, including one given
+focus back when a mouse dismisses its picker. Tab reaches an editable pill
+directly; its hover card keeps a stop only on read-only values. Real focus
+heuristics decide this, so jsdom can't cover it. The backend-free browser
+regression is
+`bunx playwright test --config src/features/property/browser-test/playwright.config.ts`.
+
Use `features/channel/channel-icon.tsx` for conversation identity in rows,
favorites, and headers: channel pictures or hashtags, human/self-DM avatars,
and bot personas share one renderer; keep surface sizing in the caller.
diff --git a/apps/web/src/components/ui/components/HoverCard.tsx b/apps/web/src/components/ui/components/HoverCard.tsx
index 5b42e71e1a..e578b02374 100644
--- a/apps/web/src/components/ui/components/HoverCard.tsx
+++ b/apps/web/src/components/ui/components/HoverCard.tsx
@@ -11,6 +11,8 @@ type HoverCardProps = ParentProps<{
placement?: Placement;
content: JSX.Element;
as?: 'div' | 'span';
+ /** Use -1 when the children hold the focusable control themselves. */
+ triggerTabIndex?: number;
/**
* When true, force the hover card closed and prevent it from opening on
* hover. Use to defer to another surface anchored on the same trigger — e.g.
@@ -59,6 +61,7 @@ export function HoverCard(props: HoverCardProps) {
contentClass="max-w-[calc(100vw-32px)]"
triggerClass={cn('inline-flex items-center', props.triggerClass)}
triggerAs={props.as ?? 'div'}
+ triggerTabIndex={props.triggerTabIndex}
disabled={props.disabled}
chokeGroup={props.chokeGroup}
/>
diff --git a/apps/web/src/features/block-md/component/Notebook.tsx b/apps/web/src/features/block-md/component/Notebook.tsx
index 3aa7877070..2d94b7783d 100644
--- a/apps/web/src/features/block-md/component/Notebook.tsx
+++ b/apps/web/src/features/block-md/component/Notebook.tsx
@@ -32,7 +32,7 @@ import {
untrack,
} from 'solid-js';
import { useMarkdownDocument } from '../context/markdown-document-context';
-import { createKeyboardFocusedControl } from '../util/createKeyboardFocusedControl';
+import { createEnterOwningControl } from '../util/createEnterOwningControl';
import { DocumentDiscussion } from './DocumentDiscussion';
import { InlineTaskGithubPullRequests } from './InlineTaskGithubPullRequests';
import { InlineTaskProperties } from './InlineTaskProperties';
@@ -99,7 +99,7 @@ export function Notebook(props: {
const { md, setMd } = state.editor;
const { displayName: documentName } = useMarkdownName();
const scopeId = () => props.hotkeyScope;
- const ownsEnter = createKeyboardFocusedControl();
+ const ownsEnter = createEnterOwningControl();
const resolveAppLink = useMacroMentionLinkResolver();
let notebookRef!: HTMLDivElement;
diff --git a/apps/web/src/features/block-md/util/createKeyboardFocusedControl.test.ts b/apps/web/src/features/block-md/util/createEnterOwningControl.test.ts
similarity index 52%
rename from apps/web/src/features/block-md/util/createKeyboardFocusedControl.test.ts
rename to apps/web/src/features/block-md/util/createEnterOwningControl.test.ts
index 81d6d12a7c..4e7ba34d42 100644
--- a/apps/web/src/features/block-md/util/createKeyboardFocusedControl.test.ts
+++ b/apps/web/src/features/block-md/util/createEnterOwningControl.test.ts
@@ -1,13 +1,13 @@
import { createRoot } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
-import { createKeyboardFocusedControl } from './createKeyboardFocusedControl';
+import { createEnterOwningControl } from './createEnterOwningControl';
let dispose = () => {};
function track() {
return createRoot((disposer) => {
dispose = disposer;
- return createKeyboardFocusedControl();
+ return createEnterOwningControl();
});
}
@@ -16,6 +16,10 @@ function add(html: string) {
return document.body.lastElementChild as HTMLElement;
}
+function press(element: Element) {
+ element.dispatchEvent(new Event('pointerdown', { bubbles: true }));
+}
+
afterEach(() => {
dispose();
document.body.replaceChildren();
@@ -50,15 +54,52 @@ it('keeps Enter for the document everywhere else', () => {
it('keeps Enter for the document after a click on a control', () => {
const ownsEnter = track();
const button = add('<button>Copy</button>');
- const matches = vi.spyOn(button, 'matches').mockReturnValue(false);
+ press(button);
button.focus();
- matches.mockRestore();
- expect(button.matches(':focus-visible')).toBe(true);
expect(ownsEnter(button)).toBe(false);
});
+it('keeps Enter for the document after a click on a control icon', () => {
+ const ownsEnter = track();
+ const button = add('<button><svg></svg></button>');
+
+ press(button.querySelector('svg') as SVGElement);
+ button.focus();
+
+ expect(ownsEnter(button)).toBe(false);
+});
+
+it('leaves Enter to a control given focus back after a press elsewhere', () => {
+ const ownsEnter = track();
+ const trigger = add('<button>Project</button>');
+ const outside = add('<div></div>');
+ // A browser doesn't count this focus as :focus-visible; jsdom always does.
+ const matches = trigger.matches.bind(trigger);
+ vi.spyOn(trigger, 'matches').mockImplementation(
+ (selector) => selector !== ':focus-visible' && matches(selector)
+ );
+
+ press(outside);
+ trigger.focus();
+
+ expect(ownsEnter(trigger)).toBe(true);
+});
+
+it('leaves Enter to a clicked control that keyboard focus comes back to', () => {
+ const ownsEnter = track();
+ const button = add('<button>Copy</button>');
+ const pane = add('<div tabindex="0"></div>');
+
+ press(button);
+ button.focus();
+ pane.focus();
+ button.focus();
+
+ expect(ownsEnter(button)).toBe(true);
+});
+
it('hands Enter back after a click on the control keyboard focus is on', () => {
const ownsEnter = track();
const button = add('<button>Copy</button>');
@@ -66,11 +107,22 @@ it('hands Enter back after a click on the control keyboard focus is on', () => {
button.focus();
expect(ownsEnter(button)).toBe(true);
- button.dispatchEvent(new Event('pointerdown', { bubbles: true }));
+ press(button);
expect(ownsEnter(button)).toBe(false);
});
+it('leaves Enter to the focused control after a press that moves no focus', () => {
+ const ownsEnter = track();
+ const button = add('<button>Project</button>');
+ const scrollbar = add('<div></div>');
+
+ button.focus();
+ press(scrollbar);
+
+ expect(ownsEnter(button)).toBe(true);
+});
+
it('forgets a control once focus moves on', () => {
const ownsEnter = track();
const button = add('<button>Open</button>');
diff --git a/apps/web/src/features/block-md/util/createEnterOwningControl.ts b/apps/web/src/features/block-md/util/createEnterOwningControl.ts
new file mode 100644
index 0000000000..583471e581
--- /dev/null
+++ b/apps/web/src/features/block-md/util/createEnterOwningControl.ts
@@ -0,0 +1,36 @@
+import { onCleanup } from 'solid-js';
+
+/**
+ * Tracks the focused control, which owns Enter unless a press focused it: Enter
+ * after a mouse click still moves on to the editor. A press focuses the nearest
+ * focusable ancestor of what it hit. `:focus-visible` can't stand in for this,
+ * because focus handed back to a control when a mouse closes its menu doesn't
+ * match it, and a pressed flag can't either, because menus hand focus back
+ * before the press ends.
+ */
+export function createEnterOwningControl() {
+ let control: Element | undefined;
+ let pressed: Node | null = null;
+ const track = ({ target }: FocusEvent) => {
+ control =
+ target instanceof Element &&
+ target.matches('button, a[href], [role="button"]') &&
+ !target.contains(pressed)
+ ? target
+ : undefined;
+ pressed = null;
+ };
+ // Clicking the focused control fires no focusin, so a press has to clear it.
+ const press = ({ target }: Event) => {
+ pressed = target instanceof Node ? target : null;
+ if (control?.contains(pressed)) control = undefined;
+ };
+ document.addEventListener('focusin', track);
+ document.addEventListener('pointerdown', press, true);
+ onCleanup(() => {
+ document.removeEventListener('focusin', track);
+ document.removeEventListener('pointerdown', press, true);
+ });
+ return (target: EventTarget | null | undefined) =>
+ control !== undefined && target === control;
+}
diff --git a/apps/web/src/features/block-md/util/createKeyboardFocusedControl.ts b/apps/web/src/features/block-md/util/createKeyboardFocusedControl.ts
deleted file mode 100644
index 4ec6f596c0..0000000000
--- a/apps/web/src/features/block-md/util/createKeyboardFocusedControl.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import { onCleanup } from 'solid-js';
-
-/**
- * Tracks the control keyboard focus landed on, which owns Enter. Read when
- * focus arrives, because Chrome makes a focused element `:focus-visible` on any
- * key press: Enter after a mouse click still moves on to the editor.
- */
-export function createKeyboardFocusedControl() {
- let control: Element | undefined;
- const track = ({ target }: FocusEvent) => {
- control =
- target instanceof Element &&
- target.matches(':focus-visible') &&
- target.matches('button, a[href], [role="button"]')
- ? target
- : undefined;
- };
- // Clicking the focused control fires no focusin, so a press has to clear it.
- const clear = () => {
- control = undefined;
- };
- document.addEventListener('focusin', track);
- document.addEventListener('pointerdown', clear, true);
- onCleanup(() => {
- document.removeEventListener('focusin', track);
- document.removeEventListener('pointerdown', clear, true);
- });
- return (target: EventTarget | null | undefined) =>
- control !== undefined && target === control;
-}
diff --git a/apps/web/src/features/property/browser-test/enter.browser.e2e.ts b/apps/web/src/features/property/browser-test/enter.browser.e2e.ts
new file mode 100644
index 0000000000..7104c2d5a5
--- /dev/null
+++ b/apps/web/src/features/property/browser-test/enter.browser.e2e.ts
@@ -0,0 +1,79 @@
+import { expect, type Locator, type Page, test } from '@playwright/test';
+
+// An open picker blocks pointer events outside it, so a locator click would
+// wait forever. A press held like a person's also keeps the pointer down while
+// the picker hands focus back.
+async function pressOn(page: Page, target: Locator) {
+ const bounds = await target.boundingBox();
+ if (!bounds) throw new Error('Press target missing');
+ await page.mouse.click(
+ bounds.x + bounds.width / 2,
+ bounds.y + bounds.height / 2,
+ { delay: 80 }
+ );
+}
+
+test.beforeEach(async ({ page }) => {
+ await page.route('**/*', async (route) => {
+ if (new URL(route.request().url()).hostname === 'localhost')
+ await route.continue();
+ else await route.fulfill({ status: 401, body: '{}' });
+ });
+ await page.routeWebSocket('**/*', (socket) => socket.close());
+ await page.goto('/src/features/property/browser-test/enter.html');
+ await expect(page.getByRole('button', { name: 'In progress' })).toBeVisible({
+ timeout: 60_000,
+ });
+});
+
+test('Enter reopens a picker after a mouse dismisses it, and typing stays there', async ({
+ page,
+}) => {
+ const pill = page.getByRole('button', { name: 'In progress' });
+ const search = page.getByLabel('Search options');
+ // An open picker hides the page from role queries, so go by label.
+ const document = page.getByLabel('Document');
+
+ await pill.click();
+ await expect(search).toBeFocused();
+ await pressOn(page, page.getByTestId('outside'));
+ await expect(search).toBeHidden();
+ await expect(pill).toBeFocused();
+
+ await page.keyboard.press('Enter');
+ await expect(search).toBeFocused();
+
+ await page.keyboard.type('q');
+ await expect(search).toHaveValue('q');
+ await expect(document).toHaveText('');
+});
+
+test('Tab reaches the pill with no stop on its hover card, and Enter opens it', async ({
+ page,
+}) => {
+ await page.keyboard.press('Tab');
+ await expect(page.getByRole('button', { name: 'In progress' })).toBeFocused();
+
+ await page.keyboard.press('Enter');
+ await expect(page.getByLabel('Search options')).toBeFocused();
+});
+
+test('a press that takes no focus leaves Enter on the pill', async ({
+ page,
+}) => {
+ await page.keyboard.press('Tab');
+ await pressOn(page, page.getByTestId('scrollbar'));
+ await expect(page.getByRole('button', { name: 'In progress' })).toBeFocused();
+
+ await page.keyboard.press('Enter');
+ await expect(page.getByLabel('Search options')).toBeFocused();
+});
+
+test('Enter right after clicking a control still moves to the document', async ({
+ page,
+}) => {
+ await page.getByRole('button', { name: 'Copy' }).click();
+
+ await page.keyboard.press('Enter');
+ await expect(page.getByRole('textbox', { name: 'Document' })).toBeFocused();
+});
diff --git a/apps/web/src/features/property/browser-test/enter.html b/apps/web/src/features/property/browser-test/enter.html
new file mode 100644
index 0000000000..3b36d73974
--- /dev/null
+++ b/apps/web/src/features/property/browser-test/enter.html
@@ -0,0 +1 @@
+<!doctype html><html><head><meta charset="UTF-8"><title>Property pill Enter fixture</title></head><body><div id="root"></div><script type="module" src="./enter.tsx"></script></body></html>
diff --git a/apps/web/src/features/property/browser-test/enter.tsx b/apps/web/src/features/property/browser-test/enter.tsx
new file mode 100644
index 0000000000..fcca4f9117
--- /dev/null
+++ b/apps/web/src/features/property/browser-test/enter.tsx
@@ -0,0 +1,96 @@
+import '@app/index.css';
+import { createEnterOwningControl } from '@block-md/util/createEnterOwningControl';
+import {
+ attachGlobalDOMScope,
+ registerHotkey,
+ useHotKeyRoot,
+ useHotkeyDOMScope,
+} from '@core/hotkey/hotkeys';
+import { Property, useProperty } from '@property';
+import { Show } from 'solid-js';
+import { render } from 'solid-js/web';
+import { EditorPopover } from '../editors/popover/EditorPopover';
+import type { Property as PropertyValue } from '../types';
+import { useSearchInputFocus } from '../utils/focus';
+
+const STATUS: PropertyValue = {
+ propertyId: 'status-property',
+ propertyDefinitionId: 'status-definition',
+ displayName: 'Status',
+ isMultiSelect: false,
+ owner: { scope: 'system' },
+ createdAt: new Date(0),
+ updatedAt: new Date(0),
+ valueType: 'SELECT_STRING',
+ value: ['in-progress'],
+};
+
+function SearchField() {
+ let input: HTMLInputElement | undefined;
+ useSearchInputFocus(() => input);
+ return <input ref={input} aria-label="Search options" />;
+}
+
+function Picker() {
+ const ctx = useProperty();
+ return (
+ <Show when={ctx.editorOpen()}>
+ <EditorPopover>
+ <SearchField />
+ </EditorPopover>
+ </Show>
+ );
+}
+
+function Fixture() {
+ useHotKeyRoot();
+ attachGlobalDOMScope(document.body);
+ const [attachScope, scopeId] = useHotkeyDOMScope('property-enter-fixture');
+ const ownsEnter = createEnterOwningControl();
+ let editor: HTMLDivElement | undefined;
+
+ // The document's own Enter, as in Notebook.
+ registerHotkey({
+ hotkey: 'enter',
+ scopeId,
+ description: 'Focus document',
+ keyDownHandler: (event) => {
+ if (ownsEnter(event?.target)) return false;
+ editor?.focus();
+ return true;
+ },
+ });
+
+ return (
+ <main ref={attachScope} class="flex flex-col items-start gap-8 p-8">
+ <Property.Root property={STATUS} canEdit onSave={async () => {}}>
+ <Property.Tooltip property={STATUS}>
+ <Property.Pill>In progress</Property.Pill>
+ </Property.Tooltip>
+ <Picker />
+ </Property.Root>
+ <button type="button">Copy</button>
+ <p data-testid="outside">Outside</p>
+ {/* A scrollbar: pressing it takes no focus. */}
+ <div
+ data-testid="scrollbar"
+ class="p-2 border"
+ onMouseDown={(event) => event.preventDefault()}
+ >
+ Scrollbar
+ </div>
+ <div
+ ref={editor}
+ role="textbox"
+ aria-label="Document"
+ contentEditable
+ tabIndex={-1}
+ class="w-80 h-20 border"
+ />
+ </main>
+ );
+}
+
+const root = document.getElementById('root');
+if (!root) throw new Error('Fixture root missing');
+render(() => <Fixture />, root);
diff --git a/apps/web/src/features/property/browser-test/playwright.config.ts b/apps/web/src/features/property/browser-test/playwright.config.ts
new file mode 100644
index 0000000000..05e431b7af
--- /dev/null
+++ b/apps/web/src/features/property/browser-test/playwright.config.ts
@@ -0,0 +1,23 @@
+import { fileURLToPath } from 'node:url';
+import { defineConfig } from '@playwright/test';
+
+const port = process.env.PROPERTY_ENTER_TEST_PORT ?? '3501';
+export default defineConfig({
+ testDir: fileURLToPath(new URL('.', import.meta.url)),
+ testMatch: '*.browser.e2e.ts',
+ workers: 1,
+ timeout: 120_000,
+ use: {
+ baseURL: `http://localhost:${port}`,
+ launchOptions: {
+ executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
+ },
+ },
+ webServer: {
+ command: `MACRO_DEV_HTTPS=false bunx vite --port ${port} --strictPort`,
+ cwd: fileURLToPath(new URL('../../../../', import.meta.url)),
+ url: `http://localhost:${port}/app/`,
+ reuseExistingServer: false,
+ timeout: 60_000,
+ },
+});
diff --git a/apps/web/src/features/property/extractors/PropertyTooltip.test.tsx b/apps/web/src/features/property/extractors/PropertyTooltip.test.tsx
new file mode 100644
index 0000000000..88ab39e654
--- /dev/null
+++ b/apps/web/src/features/property/extractors/PropertyTooltip.test.tsx
@@ -0,0 +1,79 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import userEvent from '@testing-library/user-event';
+import { afterEach, expect, it, vi } from 'vitest';
+import {
+ PropertyRootContext,
+ type PropertyRootContextValue,
+} from '../core/context';
+import type { Property } from '../types';
+import { PropertyPill } from './PropertyPill';
+import { PropertyTooltip } from './PropertyTooltip';
+
+const property: Property = {
+ propertyId: 'status-property',
+ propertyDefinitionId: 'status-definition',
+ displayName: 'Status',
+ isMultiSelect: false,
+ owner: { scope: 'system' },
+ createdAt: new Date(0),
+ updatedAt: new Date(0),
+ valueType: 'SELECT_STRING',
+ value: ['in-progress'],
+};
+
+function context(canEdit: boolean, value = property): PropertyRootContextValue {
+ return {
+ property: () => value,
+ pickedEntityName: () => undefined,
+ canEdit: () => canEdit,
+ editorOpen: () => false,
+ openEditor: vi.fn(),
+ closeEditor: vi.fn(),
+ };
+}
+
+afterEach(cleanup);
+
+it('tabs straight to an editable pill, where Enter opens its editor', async () => {
+ const user = userEvent.setup();
+ const value = context(true);
+ render(() => (
+ <PropertyRootContext.Provider value={value}>
+ <PropertyTooltip property={property}>
+ <PropertyPill>Status</PropertyPill>
+ </PropertyTooltip>
+ </PropertyRootContext.Provider>
+ ));
+
+ await user.tab();
+ expect(document.activeElement).toBe(screen.getByRole('button'));
+
+ await user.keyboard('{Enter}');
+ expect(value.openEditor).toHaveBeenCalledOnce();
+});
+
+it.each([
+ { name: 'without edit access', canEdit: false, isMetadata: false },
+ { name: 'on a metadata property', canEdit: true, isMetadata: true },
+])(
+ 'keeps a tab stop on a value that may hold no control $name',
+ async ({ canEdit, isMetadata }) => {
+ const user = userEvent.setup();
+ const value = { ...property, isMetadata };
+ render(() => (
+ <PropertyRootContext.Provider value={context(canEdit, value)}>
+ <PropertyTooltip property={value}>
+ <span>In progress</span>
+ </PropertyTooltip>
+ </PropertyRootContext.Provider>
+ ));
+
+ await user.tab();
+
+ expect(document.activeElement).toBe(screen.getByRole('link'));
+ }
+);
diff --git a/apps/web/src/features/property/extractors/PropertyTooltip.tsx b/apps/web/src/features/property/extractors/PropertyTooltip.tsx
index a6568cb349..88bd5616d8 100644
--- a/apps/web/src/features/property/extractors/PropertyTooltip.tsx
+++ b/apps/web/src/features/property/extractors/PropertyTooltip.tsx
@@ -20,6 +20,11 @@ type Props = {
* pill opens the popover anchored to the same trigger) so a click dismisses
* the hover card instead of stacking both surfaces. Reads the optional
* <Property.Root> context directly so it still works when used standalone.
+ *
+ * An editable property's control is inside the trigger, which is then no tab
+ * stop of its own: focus there looks like it is on the value, but neither Enter
+ * nor Space reaches the editor. A read-only row can have no control inside, so
+ * its trigger stays the keyboard's way to this content.
*/
export function PropertyTooltip(props: Props) {
const ctx = useContext(PropertyRootContext);
@@ -27,9 +32,11 @@ export function PropertyTooltip(props: Props) {
const trailingAction = children(() => props.trailingAction);
const hasActions = () =>
actions.toArray().length > 0 || trailingAction.toArray().length > 0;
+ const isEditable = () => ctx?.canEdit() && !ctx.property().isMetadata;
return (
<HoverCard
triggerClass="min-w-0 max-w-full"
+ triggerTabIndex={isEditable() ? -1 : undefined}
content={
<div class="min-w-0">
<CorePropertyTooltip
diff --git a/docs/agent-guide/tasks.md b/docs/agent-guide/tasks.md
index 980d6f2c38..aa723bc904 100644
--- a/docs/agent-guide/tasks.md
+++ b/docs/agent-guide/tasks.md
@@ -100,8 +100,11 @@ split, and an already open project is focused instead of opened again), and the
caret changes the project. Hovering the name turns its icon into an arrow. People
who can't edit the task get the name alone, so they can still open the project.
An empty or unavailable project keeps the plain pill, and composers never split it.
-Enter activates a pill or any other document control reached by keyboard. After a
-mouse click, Enter still moves to the editor.
+Enter activates a pill or any other document control holding focus, including one
+that gets focus back when its picker or menu closes, however it closed. After a
+mouse click on a control, Enter still moves to the editor. Tab reaches an editable
+property's pill directly, so its hover card opens on hover only; a read-only
+property keeps a stop that opens the card.
Click a task row or favorite to replace the list with the editable task document. Its top
bar shows the originating task tab as a text-only return breadcrumb,