feat(control-ui): auto-expand chat input textarea
The chat input textarea now automatically expands as you type multiple lines, up to a maximum height of 200px. This improves the user experience when composing longer messages. Changes: - Use CSS field-sizing: content for modern browsers (Chrome 123+, Firefox 131+) - Add JavaScript fallback with autoResizeTextarea() for older browsers - Disable manual resize since auto-expand handles it - Reset height when input is cleared (after sending) The textarea will: - Start at minimum height (40px) when empty - Grow automatically as content is added - Cap at max-height (200px) with overflow scroll - Shrink back when content is removed
This commit is contained in:
parent
6859e1e6a6
commit
1572183b61
@ -245,16 +245,18 @@
|
|||||||
/* Override .field textarea min-height (180px) from components.css */
|
/* Override .field textarea min-height (180px) from components.css */
|
||||||
.chat-compose .chat-compose__field textarea {
|
.chat-compose .chat-compose__field textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 40px;
|
|
||||||
min-height: 40px;
|
min-height: 40px;
|
||||||
max-height: 150px;
|
max-height: 200px;
|
||||||
padding: 9px 12px;
|
padding: 9px 12px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
resize: vertical;
|
resize: none; /* Disable manual resize since we auto-expand */
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
font-family: var(--font-body);
|
font-family: var(--font-body);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1.45;
|
line-height: 1.45;
|
||||||
|
overflow-y: auto;
|
||||||
|
box-sizing: border-box;
|
||||||
|
field-sizing: content; /* Modern CSS auto-sizing (Chrome 123+, Firefox 131+) */
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-compose__field textarea:disabled {
|
.chat-compose__field textarea:disabled {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { html, nothing } from "lit";
|
import { html, nothing } from "lit";
|
||||||
import { repeat } from "lit/directives/repeat.js";
|
import { repeat } from "lit/directives/repeat.js";
|
||||||
|
import { ref } from "lit/directives/ref.js";
|
||||||
import type { SessionsListResult } from "../types";
|
import type { SessionsListResult } from "../types";
|
||||||
import type { ChatAttachment, ChatQueueItem } from "../ui-types";
|
import type { ChatAttachment, ChatQueueItem } from "../ui-types";
|
||||||
import type { ChatItem, MessageGroup } from "../types/chat-types";
|
import type { ChatItem, MessageGroup } from "../types/chat-types";
|
||||||
@ -102,6 +103,18 @@ function generateAttachmentId(): string {
|
|||||||
return `att-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
return `att-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function autoResizeTextarea(textarea: HTMLTextAreaElement) {
|
||||||
|
// If empty, reset to default height
|
||||||
|
if (!textarea.value) {
|
||||||
|
textarea.style.height = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Reset height to auto to get the correct scrollHeight
|
||||||
|
textarea.style.height = "auto";
|
||||||
|
// Set height to scrollHeight (capped by max-height in CSS)
|
||||||
|
textarea.style.height = `${textarea.scrollHeight}px`;
|
||||||
|
}
|
||||||
|
|
||||||
function handlePaste(
|
function handlePaste(
|
||||||
e: ClipboardEvent,
|
e: ClipboardEvent,
|
||||||
props: ChatProps,
|
props: ChatProps,
|
||||||
@ -327,6 +340,9 @@ export function renderChat(props: ChatProps) {
|
|||||||
<label class="field chat-compose__field">
|
<label class="field chat-compose__field">
|
||||||
<span>Message</span>
|
<span>Message</span>
|
||||||
<textarea
|
<textarea
|
||||||
|
${ref((el) => {
|
||||||
|
if (el) autoResizeTextarea(el as HTMLTextAreaElement);
|
||||||
|
})}
|
||||||
.value=${props.draft}
|
.value=${props.draft}
|
||||||
?disabled=${!props.connected}
|
?disabled=${!props.connected}
|
||||||
@keydown=${(e: KeyboardEvent) => {
|
@keydown=${(e: KeyboardEvent) => {
|
||||||
@ -337,8 +353,11 @@ export function renderChat(props: ChatProps) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (canCompose) props.onSend();
|
if (canCompose) props.onSend();
|
||||||
}}
|
}}
|
||||||
@input=${(e: Event) =>
|
@input=${(e: Event) => {
|
||||||
props.onDraftChange((e.target as HTMLTextAreaElement).value)}
|
const textarea = e.target as HTMLTextAreaElement;
|
||||||
|
props.onDraftChange(textarea.value);
|
||||||
|
autoResizeTextarea(textarea);
|
||||||
|
}}
|
||||||
@paste=${(e: ClipboardEvent) => handlePaste(e, props)}
|
@paste=${(e: ClipboardEvent) => handlePaste(e, props)}
|
||||||
placeholder=${composePlaceholder}
|
placeholder=${composePlaceholder}
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user