Message input: textarea with Shift+Enter for newline

This commit is contained in:
Clay 2026-12-03 14:19:15 -05:00
parent 2d7b6f08ab
commit 859a8f67da
3 changed files with 16 additions and 6 deletions

View file

@ -289,6 +289,14 @@ if (styleToggleBtn) {
}); });
} }
const messageInput = document.getElementById('messageInput');
messageInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
document.getElementById('messageForm').requestSubmit();
}
});
document.getElementById('messageForm').addEventListener('submit', async (e) => { document.getElementById('messageForm').addEventListener('submit', async (e) => {
e.preventDefault(); e.preventDefault();
ui.setChatError(''); ui.setChatError('');
@ -314,6 +322,7 @@ document.getElementById('messageForm').addEventListener('submit', async (e) => {
msgId, msgId,
}); });
input.value = ''; input.value = '';
input.style.height = 'auto';
} catch (err) { } catch (err) {
ui.setChatError(err.message); ui.setChatError(err.message);
} }

View file

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web OSCAR Chat</title> <title>Web OSCAR Chat</title>
<link rel="stylesheet" href="/style.css?v=23"> <link rel="stylesheet" href="/style.css?v=24">
</head> </head>
<body> <body>
<div id="app"> <div id="app">
@ -77,7 +77,7 @@
</div> </div>
<div id="messages" class="messages" aria-live="polite"></div> <div id="messages" class="messages" aria-live="polite"></div>
<form id="messageForm" class="message-form"> <form id="messageForm" class="message-form">
<input id="messageInput" placeholder="Type a message" autocomplete="off" maxlength="2000"> <textarea id="messageInput" placeholder="Type a message (Enter to send, Shift+Enter for new line)" autocomplete="off" maxlength="2000" rows="1"></textarea>
<button type="submit">Send</button> <button type="submit">Send</button>
</form> </form>
<p id="chatError" class="error" aria-live="polite"></p> <p id="chatError" class="error" aria-live="polite"></p>
@ -86,6 +86,6 @@
</main> </main>
</div> </div>
<script type="module" src="/app.js?v=23"></script> <script type="module" src="/app.js?v=24"></script>
</body> </body>
</html> </html>

View file

@ -25,18 +25,19 @@ body {
color: var(--text); color: var(--text);
} }
input, button { input, button, textarea {
font: inherit; font: inherit;
border-radius: 8px; border-radius: 8px;
border: 1px solid var(--border); border: 1px solid var(--border);
padding: 0.55rem 0.75rem; padding: 0.55rem 0.75rem;
} }
input { input, textarea {
background: #151922; background: #151922;
color: var(--text); color: var(--text);
width: 100%; width: 100%;
} }
input:focus, button:focus { textarea { resize: vertical; min-height: 2.4rem; max-height: 10rem; }
input:focus, button:focus, textarea:focus {
outline: 2px solid rgba(77,163,255,0.35); outline: 2px solid rgba(77,163,255,0.35);
outline-offset: 1px; outline-offset: 1px;
border-color: var(--accent); border-color: var(--accent);