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(composer): open typeahead menus where their whole list fits (#8759)

gbirman637eb8150892
diff --git a/.agents/rules/web/mobile.md b/.agents/rules/web/mobile.md
index af3b99c738..e623af1104 100644
--- a/.agents/rules/web/mobile.md
+++ b/.agents/rules/web/mobile.md
@@ -73,7 +73,10 @@ read their code, and follow that pattern rather than inventing a new one.
composers, a call's control bar, desktop only) or the view around it (email
thread and composer). A composer's typeahead and picker menus (`@`, `:`,
`/`, skills, snippets, tags, GIFs) open above it and hold prompts while
- open, on every device; give a new one the same attribute on its root.
+ open, on every device; give a new one the same attribute on its root, and
+ pass `floatWithSelection` its `fullHeight` (content cap plus panel padding)
+ so it picks the side with room for its whole list instead of shrinking
+ below the caret when its first render is short.
A prompt in the transient region would cover a sheet's controls.
## Keyboard and focus
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index d3b4728dff..45f37e62ef 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -34,6 +34,11 @@ Persistent prompts stepping aside for popovers, dialogs, drawers and
`data-holds-prompts` surfaces have a backend-free browser regression:
`bunx playwright test --config src/lib/core/component/Toast/browser-test/playwright.config.ts`.
+Composer typeahead menus choosing the side with room for their full list
+(`floatWithSelection`'s `fullHeight`), above a composer at the bottom of a
+phone screen and below one near the top, have a backend-free browser regression:
+`bunx playwright test --config src/lib/core/component/LexicalMarkdown/directive/browser-test/playwright.config.ts`.
+
Meeting-note creation, linking, optional team access, retry, and unlinking have desktop and
phone browser coverage in `features/calendar-notes`:
`bunx playwright test --config src/features/calendar-notes/browser-test/playwright.config.ts`.
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
index 2b240801c2..83d9e4f85c 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
@@ -37,6 +37,7 @@ false && floatWithElement;
// Surface's p-px border (2px) + py-2 padding (16px)
const PANEL_DECORATION_HEIGHT = 18;
+const MAX_CONTENT_HEIGHT = 256;
function ActionsMenuItem(props: {
action: Action;
@@ -137,7 +138,10 @@ export function ActionMenu(props: {
const contentMaxHeight = () => {
const h = menuAvailableHeight();
if (h === undefined) return undefined;
- return Math.min(256, Math.max(0, h - PANEL_DECORATION_HEIGHT));
+ return Math.min(
+ MAX_CONTENT_HEIGHT,
+ Math.max(0, h - PANEL_DECORATION_HEIGHT)
+ );
};
const { isKeypressActive } = useIsKeyPressActive();
@@ -317,6 +321,7 @@ export function ActionMenu(props: {
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
onAvailableHeight: setMenuAvailableHeight,
+ fullHeight: MAX_CONTENT_HEIGHT + PANEL_DECORATION_HEIGHT,
}
: undefined;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
index 9ec5599a87..f19d8eaafa 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
@@ -268,6 +268,7 @@ export function EmojiMenu(props: EmojiMenuProps) {
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
onAvailableHeight: setMenuAvailableHeight,
+ fullHeight: MAX_EMOJI_LIST_HEIGHT + MENU_DECORATION_HEIGHT,
}}
use:clickOutside={() => {
closeMenu();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
index 4733962fd3..85fd08259f 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
@@ -70,6 +70,7 @@ const TARGET_ITEMS = 8;
const VIRTUAL_ITEM_HEIGHT = 36;
// Height consumed by Surface's p-px border (2px) + py-2 padding (16px)
const PANEL_DECORATION_HEIGHT = 18;
+const MAX_CONTENT_HEIGHT = 256;
const DEFAULT_DOCUMENT_BUCKETS: EntityBucket[] = [
'note',
'task',
@@ -713,7 +714,10 @@ function MentionsMenuInner(props: MentionsMenuProps) {
const contentMaxHeight = () => {
const h = menuAvailableHeight();
if (h === undefined) return undefined;
- return Math.min(256, Math.max(0, h - PANEL_DECORATION_HEIGHT));
+ return Math.min(
+ MAX_CONTENT_HEIGHT,
+ Math.max(0, h - PANEL_DECORATION_HEIGHT)
+ );
};
const floatWithElementProps = () =>
@@ -731,6 +735,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
reactiveOnContainer: props.editor?.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
onAvailableHeight: setMenuAvailableHeight,
+ fullHeight: MAX_CONTENT_HEIGHT + PANEL_DECORATION_HEIGHT,
}
: undefined;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SkillsMenu/SkillsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SkillsMenu/SkillsMenu.tsx
index eff04d3690..a91acb97b3 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SkillsMenu/SkillsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SkillsMenu/SkillsMenu.tsx
@@ -329,11 +329,14 @@ function SkillsMenuInner(props: SkillsMenuProps) {
number | undefined
>(undefined);
+ const preferredHeight = () => (props.agentCommands ? 384 : 256);
const contentMaxHeight = () => {
const h = menuAvailableHeight();
- const preferredHeight = props.agentCommands ? 384 : 256;
- if (h === undefined) return preferredHeight;
- return Math.min(preferredHeight, Math.max(0, h - PANEL_DECORATION_HEIGHT));
+ if (h === undefined) return preferredHeight();
+ return Math.min(
+ preferredHeight(),
+ Math.max(0, h - PANEL_DECORATION_HEIGHT)
+ );
};
return (
@@ -347,6 +350,7 @@ function SkillsMenuInner(props: SkillsMenuProps) {
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
onAvailableHeight: setMenuAvailableHeight,
+ fullHeight: preferredHeight() + PANEL_DECORATION_HEIGHT,
}}
use:clickOutside={() => {
closeMenu();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SnippetsMenu/SnippetsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SnippetsMenu/SnippetsMenu.tsx
index 5f182e8bf8..a8a9bd2b92 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SnippetsMenu/SnippetsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/SnippetsMenu/SnippetsMenu.tsx
@@ -32,6 +32,7 @@ false && floatWithSelection;
// Height consumed by Surface's border + vertical padding
const PANEL_DECORATION_HEIGHT = 18;
+const MAX_CONTENT_HEIGHT = 256;
type SnippetsMenuProps = {
editor: LexicalEditor;
@@ -182,8 +183,11 @@ function SnippetsMenuInner(props: SnippetsMenuProps) {
const contentMaxHeight = () => {
const h = menuAvailableHeight();
- if (h === undefined) return 256;
- return Math.min(256, Math.max(0, h - PANEL_DECORATION_HEIGHT));
+ if (h === undefined) return MAX_CONTENT_HEIGHT;
+ return Math.min(
+ MAX_CONTENT_HEIGHT,
+ Math.max(0, h - PANEL_DECORATION_HEIGHT)
+ );
};
return (
@@ -197,6 +201,7 @@ function SnippetsMenuInner(props: SnippetsMenuProps) {
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
onAvailableHeight: setMenuAvailableHeight,
+ fullHeight: MAX_CONTENT_HEIGHT + PANEL_DECORATION_HEIGHT,
}}
use:clickOutside={() => {
closeMenu();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/TagsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/TagsMenu.tsx
index 3561c21bcf..9cb65de8f7 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/TagsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/TagsMenu.tsx
@@ -37,6 +37,10 @@ import type { MenuOperations } from '../../shared/inlineMenu';
import { InlineFollowupMenu } from './InlineFollowupMenu';
import { useMenuKeyboardNavigation } from './useMenuKeyboardNavigation';
+// Surface's border + vertical padding
+const PANEL_DECORATION_HEIGHT = 18;
+const MAX_CONTENT_HEIGHT = 256;
+
type TagMenuItem = {
optionId: string;
propertyDefinitionId: string;
@@ -388,7 +392,7 @@ export function TagsMenu(props: {
const contentMaxHeight = () => {
const h = menuAvailableHeight();
if (h === undefined) return '16rem';
- return `${Math.min(256, Math.max(0, h - 18))}px`;
+ return `${Math.min(MAX_CONTENT_HEIGHT, Math.max(0, h - PANEL_DECORATION_HEIGHT))}px`;
};
return (
@@ -404,6 +408,7 @@ export function TagsMenu(props: {
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
onAvailableHeight: setMenuAvailableHeight,
+ fullHeight: MAX_CONTENT_HEIGHT + PANEL_DECORATION_HEIGHT,
}));
clickOutside(el, () => () => closeMenu());
}}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.browser.e2e.ts b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.browser.e2e.ts
new file mode 100644
index 0000000000..2001da084d
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.browser.e2e.ts
@@ -0,0 +1,34 @@
+import { expect, type Page, test } from '@playwright/test';
+
+const fixture =
+ '/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.html';
+
+async function boxes(page: Page) {
+ await expect(page.getByText('Row 12', { exact: true })).toBeAttached({
+ timeout: 30_000,
+ });
+ const menu = await page.getByTestId('menu').boundingBox();
+ const composer = await page.getByLabel('Composer').boundingBox();
+ if (!menu || !composer) throw new Error('menu or composer not laid out');
+ return { menu, composer };
+}
+
+test('a menu that opens short over a bottom composer goes above it at full height', async ({
+ page,
+}) => {
+ await page.goto(fixture);
+ const { menu, composer } = await boxes(page);
+
+ expect(menu.y + menu.height).toBeLessThanOrEqual(composer.y);
+ expect(menu.height).toBeGreaterThanOrEqual(256);
+});
+
+test('a menu under a composer near the top still opens below it', async ({
+ page,
+}) => {
+ await page.goto(`${fixture}?caret=top`);
+ const { menu, composer } = await boxes(page);
+
+ expect(menu.y).toBeGreaterThanOrEqual(composer.y + composer.height);
+ expect(menu.height).toBeGreaterThanOrEqual(256);
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.html b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.html
new file mode 100644
index 0000000000..5231ada6e2
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.html
@@ -0,0 +1,5 @@
+<!doctype html>
+<html lang="en">
+ <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Composer menu placement fixture</title></head>
+ <body><div id="root"></div><script type="module" src="./composer-menu.tsx"></script></body>
+</html>
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.tsx
new file mode 100644
index 0000000000..d47ef9e06e
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.tsx
@@ -0,0 +1,82 @@
+import '@app/index.css';
+import { createSignal, For, onMount, Show } from 'solid-js';
+import { render } from 'solid-js/web';
+import { floatWithSelection } from '../floatWithSelection';
+
+const PANEL_DECORATION_HEIGHT = 18;
+const MAX_CONTENT_HEIGHT = 256;
+
+function Menu(props: { rows: number }) {
+ const [availableHeight, setAvailableHeight] = createSignal<number>();
+ const contentMaxHeight = () => {
+ const h = availableHeight();
+ if (h === undefined) return MAX_CONTENT_HEIGHT;
+ return Math.min(
+ MAX_CONTENT_HEIGHT,
+ Math.max(0, h - PANEL_DECORATION_HEIGHT)
+ );
+ };
+ return (
+ <div
+ data-testid="menu"
+ class="w-64 z-modal-content"
+ ref={(el) =>
+ floatWithSelection(el, () => ({
+ selection: document.getSelection(),
+ onAvailableHeight: setAvailableHeight,
+ fullHeight: MAX_CONTENT_HEIGHT + PANEL_DECORATION_HEIGHT,
+ }))
+ }
+ >
+ <div class="menu-surface rounded-xl p-px py-2">
+ <div
+ class="overflow-y-auto"
+ style={{ 'max-height': `${contentMaxHeight()}px` }}
+ >
+ <For each={Array.from({ length: props.rows }, (_, i) => i + 1)}>
+ {(row) => <div class="flex h-9 items-center px-2">Row {row}</div>}
+ </For>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+// A composer near the bottom (above a dock) or near the top of a phone
+// screen. Its menu opens with one row, as a list filtered by a stale term
+// does, and grows to its full list a moment later.
+function Fixture() {
+ const caretAtTop =
+ new URLSearchParams(location.search).get('caret') === 'top';
+ const [open, setOpen] = createSignal(false);
+ const [rows, setRows] = createSignal(1);
+ let composer!: HTMLDivElement;
+ onMount(() => {
+ composer.focus();
+ const range = document.createRange();
+ range.selectNodeContents(composer);
+ range.collapse(false);
+ document.getSelection()?.removeAllRanges();
+ document.getSelection()?.addRange(range);
+ setOpen(true);
+ setTimeout(() => setRows(12), 100);
+ });
+ return (
+ <main class="relative h-screen bg-page text-ink">
+ <div
+ ref={composer}
+ contentEditable
+ aria-label="Composer"
+ class="absolute inset-x-4 h-10 rounded-full border border-edge px-4 leading-10"
+ style={caretAtTop ? { top: '80px' } : { bottom: '80px' }}
+ >
+ /
+ </div>
+ <Show when={open()}>
+ <Menu rows={rows()} />
+ </Show>
+ </main>
+ );
+}
+
+render(() => <Fixture />, document.getElementById('root')!);
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/playwright.config.ts b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/playwright.config.ts
new file mode 100644
index 0000000000..20df41a0d4
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/playwright.config.ts
@@ -0,0 +1,31 @@
+import { fileURLToPath } from 'node:url';
+import { defineConfig } from '@playwright/test';
+
+const webDirectory = fileURLToPath(
+ new URL('../../../../../../../', import.meta.url)
+);
+const port = process.env.FLOAT_WITH_SELECTION_TEST_PORT ?? '3051';
+
+export default defineConfig({
+ testDir: fileURLToPath(new URL('.', import.meta.url)),
+ testMatch: '*.browser.e2e.ts',
+ workers: 1,
+ timeout: 60_000,
+ use: {
+ baseURL: `http://localhost:${port}`,
+ headless: true,
+ viewport: { width: 390, height: 844 },
+ hasTouch: true,
+ isMobile: true,
+ launchOptions: {
+ executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
+ },
+ },
+ webServer: {
+ command: `MACRO_DEV_HTTPS=false bunx vite --port ${port} --strictPort`,
+ cwd: webDirectory,
+ url: `http://localhost:${port}/app/`,
+ reuseExistingServer: false,
+ timeout: 60_000,
+ },
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts
index 185108dcee..a26d94b9a3 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts
@@ -11,6 +11,7 @@ import {
offset,
type Placement,
shift,
+ size,
} from '@floating-ui/dom';
import { Telemetry } from '@macro-inc/observability';
import type { Accessor, JSX } from 'solid-js';
@@ -39,6 +40,13 @@ type FloatWithSelectionOptions = {
floatingOptions?: Partial<ComputePositionConfig>;
moveWithSelection?: boolean;
onAvailableHeight?: (height: number) => void;
+ /**
+ * The menu's height with its whole list. It opens below the caret when that
+ * height (or what it renders, if taller) fits there and above when there is
+ * more room above: a list that renders short and then grows would otherwise
+ * stay below the caret and shrink.
+ */
+ fullHeight?: number;
};
export function floatWithSelection(
@@ -59,6 +67,40 @@ export function floatWithSelection(
);
let decidedPlacement: Placement | null = null;
+ async function roomOn(
+ anchor: Range | Element,
+ placement: Placement,
+ spacing: number
+ ) {
+ let room = 0;
+ await computePosition(anchor, floatingEl, {
+ placement,
+ middleware: [
+ offset(spacing),
+ size({
+ boundary,
+ padding: iosSafePadding(spacing),
+ apply: ({ availableHeight }) => {
+ room = availableHeight;
+ },
+ }),
+ ],
+ });
+ return room;
+ }
+
+ async function sideWithRoomFor(
+ anchor: Range | Element,
+ fullHeight: number,
+ spacing: number
+ ): Promise<Placement> {
+ const height = Math.max(fullHeight, floatingEl.offsetHeight);
+ const below = await roomOn(anchor, 'bottom-start', spacing);
+ if (below >= height) return 'bottom-start';
+ const above = await roomOn(anchor, 'top-start', spacing);
+ return above > below ? 'top-start' : 'bottom-start';
+ }
+
async function setInitialFloatingPosition(
selection: Selection | null | undefined
) {
@@ -81,6 +123,12 @@ export function floatWithSelection(
if (anchor) {
setCurrentAnchor(anchor);
const spacing = accessor()?.spacing ?? DEFAULT_SPACING;
+ const fullHeight = accessor()?.fullHeight;
+ if (fullHeight !== undefined) {
+ decidedPlacement = await sideWithRoomFor(anchor, fullHeight, spacing);
+ await updatePosition();
+ return;
+ }
const floatingOptions = accessor()?.floatingOptions ?? {};
const preferredPlacement = floatingOptions.placement ?? 'bottom-start';
const { placement } = await computePosition(anchor, floatingEl, {