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: autofocus new Agent input on mobile (#4985)

Peter Chinman7164964a9031
diff --git a/apps/web/src/features/command/Launcher.tsx b/apps/web/src/features/command/Launcher.tsx
index d6e927f9ad..363e22f1df 100644
--- a/apps/web/src/features/command/Launcher.tsx
+++ b/apps/web/src/features/command/Launcher.tsx
@@ -4,6 +4,7 @@ import { EMAIL_COMPOSE_TO_INPUT_ID } from '@block-email/constants';
import { openNewChannelModal } from '@channel/CreateChannelModal';
import { useSplitLayout } from '@components/app/split-layout/layout';
import type { BlockAlias, BlockName } from '@core/block';
+import { CHAT_INPUT_TEXT_AREA_ID } from '@core/component/AI/component/input/ChatInput';
import { getIconConfig } from '@core/component/EntityIcon';
import {
ENABLE_ANIMATED_ICONS,
@@ -237,6 +238,16 @@ export function runCreateAction(
});
return;
case 'chat':
+ // On mobile the chat input doesn't autofocus on mount, so arm focus
+ // within this gesture (iOS only raises the keyboard for a synchronous
+ // focus). The chat mounts asynchronously, so this waits for the input.
+ if (isMobile()) {
+ triggerFocusInput(() =>
+ document
+ .getElementById(CHAT_INPUT_TEXT_AREA_ID)
+ ?.querySelector<HTMLElement>('[contenteditable="true"]')
+ );
+ }
createBlock({
blockName: 'chat',
createFn: async () => {
diff --git a/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx b/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
index 02b2f452cb..e4a2777003 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
@@ -29,6 +29,12 @@ import { AttachmentList } from './Attachment';
import { ChatAttachMenu } from './ChatAttachMenu';
import { useAiDataConsentGate } from './useAiDataConsent';
+/**
+ * Id of the chat input's text-area wrapper. Exposed so callers (e.g. the
+ * mobile Create menu) can arm focus on the contenteditable before it mounts.
+ */
+export const CHAT_INPUT_TEXT_AREA_ID = 'chat-input-text-area';
+
type ChatInputProps = {
onSend: (args: ChatSendInput) => void;
onStop?: () => void;
@@ -337,7 +343,7 @@ export function ChatInput(props: ChatInputComponentProps) {
</div>
</Show>
<div
- id="chat-input-text-area"
+ id={CHAT_INPUT_TEXT_AREA_ID}
class={cn('text-sm sm:text-sm text-ink')}
classList={{
'pl-8': !isMultiline() && !isTallVariant(),