fix(site): disable chat input editor on archived agent chats (#22609)

This commit is contained in:
Danielle Maywood
2026-03-04 16:19:18 +00:00
committed by GitHub
parent 8a1dd518db
commit 619023f5fc
2 changed files with 26 additions and 1 deletions
@@ -27,6 +27,7 @@ import {
useCallback,
useEffect,
useImperativeHandle,
useLayoutEffect,
useMemo,
useRef,
} from "react";
@@ -221,6 +222,21 @@ interface ChatMessageInputProps
"aria-label"?: string;
}
// Keeps the Lexical editor's editable state in sync with the
// disabled prop so that the underlying contentEditable element
// becomes truly non-interactive when the input is disabled.
const EditableStatePlugin: FC<{ disabled: boolean }> = memo(
function EditableStatePlugin({ disabled }) {
const [editor] = useLexicalComposerContext();
useLayoutEffect(() => {
editor.setEditable(!disabled);
}, [editor, disabled]);
return null;
},
);
const ChatMessageInput = memo(
({
className,
@@ -243,8 +259,9 @@ const ChatMessageInput = memo(
},
onError: (error: Error) => console.error("Lexical error:", error),
nodes: [],
editable: !disabled,
}),
[],
[disabled],
);
const style = useMemo(
() => ({
@@ -380,6 +397,7 @@ const ChatMessageInput = memo(
<ContentChangePlugin onChange={handleContentChange} />
<ValueSyncPlugin initialValue={initialValue} />
<InsertTextPlugin onEditorReady={handleEditorReady} />
<EditableStatePlugin disabled={!!disabled} />
{autoFocus && <AutoFocusPlugin />}
</div>
</LexicalComposer>
@@ -80,6 +80,13 @@ export const DisabledInput: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
expect(canvas.getByRole("button", { name: "Send" })).toBeDisabled();
// The editor should be non-editable so users cannot click
// into it and type (e.g. archived chats).
const editor = canvas.getByTestId("chat-message-input");
await waitFor(() => {
expect(editor).toHaveAttribute("contenteditable", "false");
});
},
};