Skip to content

Commit fb79954

Browse files
fix(command-center): stop focus from scrolling the cell on click (#3009)
1 parent d2fea88 commit fb79954

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/ui/src/features/command-center/components/CommandCenterGrid.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ function GridCell({
8080
}
8181
const selection = window.getSelection();
8282
if (selection && !selection.isCollapsed) return;
83-
cellRef.current?.querySelector<HTMLElement>("[tabindex='0']")?.focus();
83+
cellRef.current
84+
?.querySelector<HTMLElement>("[tabindex='0']")
85+
?.focus({ preventScroll: true });
8486
},
8587
[markActive],
8688
);

packages/ui/src/features/message-editor/tiptap/useDraftSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export function useDraftSync(
169169
if (!editor || !pendingContent) return;
170170

171171
editor.commands.setContent(editorContentToTiptapJson(pendingContent));
172-
editor.commands.focus("end");
172+
editor.commands.focus("end", { scrollIntoView: false });
173173
draftActions.clearPendingContent(sessionId);
174174
}, [editor, pendingContent, sessionId, draftActions]);
175175

packages/ui/src/features/message-editor/tiptap/useTiptapEditor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,9 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
615615

616616
const focus = useCallback(() => {
617617
if (editor?.view) {
618-
editor.commands.focus("end");
618+
// scrollIntoView:false keeps a focus request from yanking the viewport
619+
// when the composer is off-screen (e.g. embedded in a command-center cell).
620+
editor.commands.focus("end", { scrollIntoView: false });
619621
}
620622
}, [editor]);
621623
const blur = useCallback(() => editor?.commands.blur(), [editor]);
@@ -630,7 +632,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
630632
(text: string) => {
631633
if (!editor) return;
632634
editor.commands.setContent(text);
633-
editor.commands.focus("end");
635+
editor.commands.focus("end", { scrollIntoView: false });
634636
draft.saveDraft(editor, attachments);
635637
},
636638
[editor, draft, attachments],

0 commit comments

Comments
 (0)