Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email-compose): stop Enter from adding a different contact than the address typed (#9296)
teo382104ef2db8
diff --git a/apps/web/src/features/email-compose/components/compose-recipient-input.tsx b/apps/web/src/features/email-compose/components/compose-recipient-input.tsxindex 3da3626015..ea6c4b14d7 100644--- a/apps/web/src/features/email-compose/components/compose-recipient-input.tsx+++ b/apps/web/src/features/email-compose/components/compose-recipient-input.tsx@@ -15,6 +15,7 @@ export function ComposeRecipientInput(noPaddingopenOnFocus={props.openOnFocus ?? false}hideMenuOnEscape+ showChipAddressesclass={cn('bg-transparent [&_input]:ml-0!', props.class)}/>);diff --git a/apps/web/src/features/email-compose/views/reply-envelope.tsx b/apps/web/src/features/email-compose/views/reply-envelope.tsxindex 5bc8eddd7f..6b6a8598eb 100644--- a/apps/web/src/features/email-compose/views/reply-envelope.tsx+++ b/apps/web/src/features/email-compose/views/reply-envelope.tsx@@ -115,6 +115,7 @@ export function ReplyEnvelope(props: ReplyEnvelopeProps) {}onChipDragEnd={handleChipDragEnd}hideMenuOnEscape+ showChipAddresses/>);return (diff --git a/apps/web/src/lib/core/component/RecipientSelector.ranking.test.tsx b/apps/web/src/lib/core/component/RecipientSelector.ranking.test.tsxindex d5088c02ba..7c4c5bf9a0 100644--- a/apps/web/src/lib/core/component/RecipientSelector.ranking.test.tsx+++ b/apps/web/src/lib/core/component/RecipientSelector.ranking.test.tsx@@ -137,6 +137,40 @@ it.each(inboxes)(});+it.each(inboxes)(+ 'adds the typed address on Enter after contacts load and reorder in a $provider inbox',+ async ({ address }) => {+ const [options, setOptions] = createSignal<CombinedRecipientItem[]>([]);+ const [selected, setSelected] = createSignal<WithCustomUserInput[]>([]);+ render(() => (+ <RecipientSelector+ options={options}+ selfEmail={address}+ selectedOptions={selected()}+ setSelectedOptions={setSelected}+ openOnFocus={false}+ />+ ));+ const input = screen.getByRole<HTMLInputElement>('combobox');+ fireEvent.input(input, { target: { value: '[email protected]' } });+ await screen.findByRole('listbox');+ setOptions([+ contact('[email protected]', 'sam'),+ contact('[email protected]', 'Sam Rivera'),+ ]);+ await screen.findByRole('option', { name: /contoso-test/ });+ fireEvent.keyDown(input, { key: 'Enter' });++ await waitFor(() =>+ expect(+ selected().map((option) =>+ 'email' in option.data ? option.data.email : ''+ )+ ).toEqual(['[email protected]'])+ );+ }+);+it.each(inboxes)('suggests a contact whose name starts with the query near the top in a $provider inbox',async ({ address }) => {diff --git a/apps/web/src/lib/core/component/RecipientSelector.tsx b/apps/web/src/lib/core/component/RecipientSelector.tsxindex 62a23f986f..b3b28610e0 100644--- a/apps/web/src/lib/core/component/RecipientSelector.tsx+++ b/apps/web/src/lib/core/component/RecipientSelector.tsx@@ -59,6 +59,7 @@ function ChipWithUserTooltip(props: {open={open()}onOpenChange={setOpen}triggerAs="div"+ triggerClass="max-w-full"trigger={props.chip}content={props.renderTooltip(() => setOpen(false))}// Chips mount under the cursor when a recipient is picked via keyboard;@@ -72,6 +73,7 @@ function RecipientChip(props: {icon?: JSX.Element;label: string;address?: string;+ showAddress?: boolean;onRemove: () => void;draggable?: boolean;onDragStart?: (e: DragEvent) => void;@@ -79,18 +81,28 @@ function RecipientChip(props: {}) {return (<div- class="flex flex-row shrink-0 py-1 pl-2 gap-1 pr-1 overflow-hidden items-center bg-active rounded-full"+ class="flex flex-row shrink-0 max-w-full py-1 pl-2 gap-1 pr-1 overflow-hidden items-center bg-active rounded-full"draggable={props.draggable}onDragStart={props.onDragStart}onDragEnd={props.onDragEnd}><Show when={props.icon}>{props.icon}</Show>- <p class="text-sm whitespace-nowrap">{truncateString(props.label, 20)}</p>+ <p class="min-w-0 truncate text-sm">{truncateString(props.label, 20)}</p><Show when={props.address}>- {(address) => <span class="sr-only">{address()}</span>}+ {(address) => (+ <span+ class={+ props.showAddress+ ? 'min-w-0 truncate text-sm text-ink-muted'+ : 'sr-only'+ }+ >+ {address()}+ </span>+ )}</Show><XIcon- class="size-5 hover:bg-hover hover:text-failure p-1 rounded-full"+ class="size-5 shrink-0 hover:bg-hover hover:text-failure p-1 rounded-full"onClick={props.onRemove}/></div>@@ -417,6 +429,8 @@ export type RecipientSelectorProps<K extends CombinedRecipientKind> = {inviteExternalEmails?: boolean;/** Messages can target only existing users or channels. Defaults to true. */allowCustomRecipients?: boolean;+ /** Show each person's address beside their name on chips, as email does. */+ showChipAddresses?: boolean;};export function RecipientSelector<K extends CombinedRecipientKind>(@@ -716,11 +730,11 @@ export function RecipientSelector<K extends CombinedRecipientKind>(let contentEl: HTMLElement | undefined;- // Committing changes the selection, and Kobalte clears the input when it does.- const commitSeparatedEmails = (input: string) => {- if (!/[,;]\s*$/.test(input)) return false;- const emails = input- .split(/[,;]/)+ // Adds each typed address as the known recipient with that address, or as a+ // typed one. Committing changes the selection, and Kobalte clears the input+ // when it does.+ const commitEmails = (parts: string[]) => {+ const emails = parts.map((part) => part.trim()).filter(Boolean).filter(@@ -764,7 +778,21 @@ export function RecipientSelector<K extends CombinedRecipientKind>(return true;};+ const commitSeparatedEmails = (input: string) =>+ /[,;]\s*$/.test(input) && commitEmails(input.split(/[,;]/));++ // Contacts and names load after the field opens and reorder the rows, so a+ // row the pointer rests on can change under it. Enter on a complete address+ // adds that address unless an arrow key picked another row since the edit.+ let rowPickedByKey = false;+ const commitTypedAddressOnEnter = (e: KeyboardEvent) => {+ if (rowPickedByKey || e.isComposing) return false;+ if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return false;+ return commitEmails([inputValue()]);+ };+const onInputChange = (next: string) => {+ rowPickedByKey = false;props.onInputChange?.(next);if (commitSeparatedEmails(next)) {setInputValue('');@@ -876,6 +904,7 @@ export function RecipientSelector<K extends CombinedRecipientKind>(? undefined}+ showAddress={props.showChipAddresses}onRemove={() => state.remove(option)}draggable={!!props.onChipDragStart}onDragStart={(e) =>@@ -1029,6 +1058,20 @@ export function RecipientSelector<K extends CombinedRecipientKind>(return;}+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ rowPickedByKey = true;+ }++ if (+ e.key === 'Enter' &&+ context.isOpen() &&+ commitTypedAddressOnEnter(e)+ ) {+ e.preventDefault();+ context.close();+ return;+ }+if (e.key === 'Tab' && context.isOpen()) {e.preventDefault();e.stopPropagation();diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.mdindex c3529a7df7..1e3f4a411a 100644--- a/docs/agent-guide/email.md+++ b/docs/agent-guide/email.md@@ -80,8 +80,10 @@ waiting for reconnect, so pressing them again works at once.Recipient fields turn complete addresses into chips when the typed or pastedtext ends in a comma or semicolon, so `[email protected], [email protected],` adds both.-Enter or a click picks the highlighted suggestion. Type, paste, or Tab straight-after picking one and check that both recipients stay and the input is empty.+Enter or a click picks the highlighted suggestion; on a complete typed address,+Enter or Tab adds that address unless an arrow key picked another row. Type,+paste, or Tab straight after picking one and check that both recipients stay+and the input is empty.Outlook connections support personal Outlook.com and individual Microsoft 365inboxes. Choose the inbox explicitly when testing mixed-provider accounts. The@@ -672,10 +674,13 @@ written message and these controls on desktop and mobile, where sending insertsthe signature above the quoted thread on Gmail and Outlook.Check recipient suggestions from a Gmail and an Outlook inbox. Typing a fulladdress and pressing Enter commits that address, ahead of longer matches such-as `[email protected]`, whether or not it is a saved contact. A name or-address word that starts with the query ranks above recent substring matches-(`gab` finds Gab Rowan). Opened empty, the list puts colleagues on the sending-inbox's domain first. A chip shows the name and its hover card the address.+as `[email protected]`, whether or not it is a saved contact. That holds+when contacts or their names load after typing starts and reorder the list,+including under a resting pointer, and when the address was typed or pasted+before suggestions loaded. A name or address word that starts with the query+ranks above recent substring matches (`gab` finds Gab Rowan). Opened empty,+the list puts colleagues on the sending inbox's domain first. A chip shows the+name followed by the address in muted ink.Press Send with To empty, then add a recipient: the error clears at once, as amissing message or subject error does once filled in. Suggestions leave outautomated addresses (`notifications@`, `mailer-daemon@`, `postmaster@`,