-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: Add multiline support to Chat component #2749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds multiline support to the Chat component, allowing users to insert newlines using Ctrl+Enter or Cmd+Enter while preserving the existing behavior where Enter sends the message. The implementation converts the input field to a multiline textarea and ensures newlines are properly rendered in markdown mode.
Key Changes
- Converted Chat input from single-line to multiline TextField with configurable row limits (1-4 rows)
- Implemented Ctrl+Enter and Cmd+Enter keyboard shortcuts to insert newlines at cursor position
- Added newline-to-markdown conversion for proper rendering in markdown mode
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/taipy-gui/src/components/Taipy/Chat.tsx | Converted TextField to multiline, added keyboard handling for newline insertion, updated type signatures from HTMLInputElement to HTMLTextAreaElement, and implemented newline-to-markdown conversion |
| frontend/taipy-gui/src/components/Taipy/Chat.spec.tsx | Updated existing test to expect textarea instead of input, added comprehensive tests for Ctrl+Enter, Cmd+Enter, multiple newlines, backwards compatibility, and newline preservation in different modes |
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| textarea.dispatchEvent(new Event('input', { bubbles: true })); | ||
| } | ||
| evt.preventDefault(); | ||
| } else { |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keyboard handling logic has changed behavior for modifier keys. The original code only sent messages when Enter was pressed with NO modifier keys (!evt.shiftKey && !evt.ctrlKey && !evt.altKey). The new code will send messages when Enter is pressed with Shift or Alt (without Ctrl/Meta).
This means Shift+Enter and Alt+Enter will now send the message instead of being ignored. Consider updating the condition to preserve the original behavior:
if (ENTER_KEY == evt.key) {
if (evt.ctrlKey || evt.metaKey) {
// insert newline at cursor
const textarea = evt.currentTarget.querySelector("textarea") as HTMLTextAreaElement;
if (textarea) {
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const value = textarea.value;
textarea.value = value.substring(0, start) + '\n' + value.substring(end);
textarea.setSelectionRange(start + 1, start + 1);
textarea.dispatchEvent(new Event('input', { bubbles: true }));
}
evt.preventDefault();
} else if (!evt.shiftKey && !evt.altKey) {
// only send if no other modifiers are pressed
sendAction(evt.currentTarget.querySelector("textarea"), evt.key);
evt.preventDefault();
}
}| } else { | |
| } else if (!evt.shiftKey && !evt.altKey) { | |
| // only send if no other modifiers are pressed |
What type of PR is this? (Check all that apply)
Description
Fixes #2579 by adding multiline support to the Chat component.
The new behavior is that Ctrl+Enter or Cmd+Enter inserts a newline at the point of selection, while Enter still sends the message (for backwards compatibility). The newlines are also preserved in the rendered chat messages, and test cases have been added for the new feature.
Related Tickets & Documents
How to reproduce the issue
Here's a very simple interface which I've used for testing:
Run this script! Then type some text, press Ctrl+Enter or Cmd+Enter on a Mac, and verify that a newline is being inserted at cursor position. Enter should still send the chat message, and it will be echoed with the newlines preserved. Copypasting some text with newlines present in it should work as well.
Backporting
This change should be backported to:
Checklist
We encourage keeping the code coverage percentage at 80% or above.
If not, explain why:
If not, explain why: covered in unit tests
If not, explain why: unsure where this would be covered, but I can update the relevant docs :)
If not, explain why: l believe this is done by a maintainer later on?