Add auti-resizing input

This commit is contained in:
Niek van der Maas 2023-03-05 16:54:57 +01:00
parent 0074ff0de1
commit 48ce3d96af
2 changed files with 15 additions and 2 deletions

View File

@ -33,6 +33,11 @@ a.is-disabled {
text-decoration: none !important; text-decoration: none !important;
} }
/* Style the chat input */
.chat-input {
overflow-y:hidden;
}
$footer-padding: 3rem 1.5rem; $footer-padding: 3rem 1.5rem;
@import "/node_modules/bulma/bulma.sass"; @import "/node_modules/bulma/bulma.sass";

View File

@ -107,7 +107,7 @@
</script> </script>
<nav class="level is-mobile chat-header"> <nav class="level is-mobile chat-header">
<div class="level-left chatname"> <div class="level-left">
<div class="level-item"> <div class="level-item">
<p class="subtitle is-5"> <p class="subtitle is-5">
{chat.name} {chat.name}
@ -184,16 +184,24 @@
<form class="field has-addons has-addons-right" on:submit|preventDefault={send}> <form class="field has-addons has-addons-right" on:submit|preventDefault={send}>
<p class="control is-expanded"> <p class="control is-expanded">
<textarea <textarea
class="input is-info is-medium is-focused" class="input is-info is-medium is-focused chat-input"
placeholder="Type your message here..." placeholder="Type your message here..."
rows="1" rows="1"
on:keydown={(e) => { on:keydown={(e) => {
// Only send if Enter is pressed, not Shift+Enter // Only send if Enter is pressed, not Shift+Enter
if (e.key === "Enter" && !e.shiftKey) { if (e.key === "Enter" && !e.shiftKey) {
send(); send();
// Resize back to auto
// @ts-ignore
e.target.style.height = "auto";
e.preventDefault(); e.preventDefault();
} }
}} }}
on:input={(e) => {
// Resize the textarea to fit the content
// @ts-ignore
e.target.style.height = e.target.scrollHeight + "px";
}}
bind:this={input} bind:this={input}
/> />
</p> </p>