fix(ui): restore composer focus after CodeMirror migration
This commit is contained in:
@@ -504,6 +504,7 @@ export const ComposerEditor = React.forwardRef<ComposerEditorHandle, ComposerEdi
|
||||
<div
|
||||
ref={hostRef}
|
||||
data-testid={props['data-testid']}
|
||||
data-chat-input="true"
|
||||
onMouseDown={handleHostMouseDown}
|
||||
className={cn(
|
||||
'composer-editor w-full',
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { afterEach, expect, test } from 'bun:test';
|
||||
|
||||
import { focusChatInput } from '../dom';
|
||||
|
||||
const originalDocument = globalThis.document;
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.document = originalDocument;
|
||||
});
|
||||
|
||||
test('focuses the CodeMirror chat input content', () => {
|
||||
let selector = '';
|
||||
let focused = false;
|
||||
globalThis.document = {
|
||||
querySelector: (value: string) => {
|
||||
selector = value;
|
||||
return { focus: () => { focused = true; } };
|
||||
},
|
||||
} as unknown as Document;
|
||||
|
||||
focusChatInput();
|
||||
|
||||
expect(selector).toBe('[data-chat-input="true"] .cm-content');
|
||||
expect(focused).toBe(true);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
const CHAT_INPUT_EDITOR_SELECTOR = '[data-chat-input="true"] .cm-content';
|
||||
|
||||
export function focusChatInput(): void {
|
||||
document.querySelector<HTMLElement>(CHAT_INPUT_EDITOR_SELECTOR)?.focus();
|
||||
}
|
||||
Reference in New Issue
Block a user