Message input: textarea with Shift+Enter for newline
This commit is contained in:
parent
2d7b6f08ab
commit
859a8f67da
3 changed files with 16 additions and 6 deletions
|
|
@ -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) => {
|
||||
e.preventDefault();
|
||||
ui.setChatError('');
|
||||
|
|
@ -314,6 +322,7 @@ document.getElementById('messageForm').addEventListener('submit', async (e) => {
|
|||
msgId,
|
||||
});
|
||||
input.value = '';
|
||||
input.style.height = 'auto';
|
||||
} catch (err) {
|
||||
ui.setChatError(err.message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Web OSCAR Chat</title>
|
||||
<link rel="stylesheet" href="/style.css?v=23">
|
||||
<link rel="stylesheet" href="/style.css?v=24">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
|
|
@ -77,7 +77,7 @@
|
|||
</div>
|
||||
<div id="messages" class="messages" aria-live="polite"></div>
|
||||
<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>
|
||||
</form>
|
||||
<p id="chatError" class="error" aria-live="polite"></p>
|
||||
|
|
@ -86,6 +86,6 @@
|
|||
</main>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/app.js?v=23"></script>
|
||||
<script type="module" src="/app.js?v=24"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -25,18 +25,19 @@ body {
|
|||
color: var(--text);
|
||||
}
|
||||
|
||||
input, button {
|
||||
input, button, textarea {
|
||||
font: inherit;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border);
|
||||
padding: 0.55rem 0.75rem;
|
||||
}
|
||||
input {
|
||||
input, textarea {
|
||||
background: #151922;
|
||||
color: var(--text);
|
||||
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-offset: 1px;
|
||||
border-color: var(--accent);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue