Commit 06cdf51a authored by Alain Takoudjou's avatar Alain Takoudjou

Auto expand chat input when text is growing

Expand textarea input up to 4 lines when message is fill the input, based on the approach here https://css-tricks.com/the-cleanest-trick-for-autogrowing-textareas/, we replicate textarea content in an hidden element which will expand textarea size when then text content grow.
parent 5c2e27b2
...@@ -289,7 +289,6 @@ ...@@ -289,7 +289,6 @@
} }
.reply { .reply {
height: 53px;
width: 100%; width: 100%;
background-color: #eae7e5; background-color: #eae7e5;
padding: 10px 5px 10px 5px; padding: 10px 5px 10px 5px;
...@@ -297,8 +296,29 @@ ...@@ -297,8 +296,29 @@
z-index: 1000; z-index: 1000;
} }
.reply textarea { .reply-button {
width: 100%; flex: 0 43px;
}
.reply-wrap {
display: grid;
flex: 1;
margin-right: .5em;
}
.reply-wrap::after {
content: attr(data-replicated-value) " ";
white-space: pre-wrap;
visibility: hidden;
}
.reply-wrap > textarea,
.reply-wrap::after {
/* Identical styling required!! */
font: inherit;
/* Place on top of each other */
grid-area: 1 / 1 / 2 / 2;
max-height: 100px;
resize: none; resize: none;
overflow: hidden; overflow: hidden;
padding: 5px; padding: 5px;
...@@ -309,15 +329,9 @@ ...@@ -309,15 +329,9 @@
height: 100%; height: 100%;
} }
textarea.form-reply {
height: 2.1em;
margin-right: .5em;
}
.form-reply { .form-reply {
display: block; display: block;
width: 100%; width: 100%;
height: 34px;
padding: 6px 12px; padding: 6px 12px;
font-size: 1rem; font-size: 1rem;
color: #555; color: #555;
...@@ -797,6 +811,8 @@ h1 { ...@@ -797,6 +811,8 @@ h1 {
#chatbox { #chatbox {
height: 100%; height: 100%;
position: relative; position: relative;
display: flex;
flex-direction: column;
} }
#chat { #chat {
...@@ -820,7 +836,7 @@ h1 { ...@@ -820,7 +836,7 @@ h1 {
#box { #box {
overflow: auto; overflow: auto;
height: calc(100% - 53px); height: 100%;
padding: 10px; padding: 10px;
} }
...@@ -851,7 +867,7 @@ h1 { ...@@ -851,7 +867,7 @@ h1 {
width: 100%; width: 100%;
border: none; border: none;
resize: none; resize: none;
overflow-y: hidden; overflow-y: auto;
} }
#input:focus { #input:focus {
......
...@@ -78,8 +78,12 @@ ...@@ -78,8 +78,12 @@
<div id="box"></div> <div id="box"></div>
<div class="reply"> <div class="reply">
<form id="inputform"> <form id="inputform">
<textarea id="input" class="form-reply"></textarea> <div class="reply-wrap">
<textarea rows="1" id="input" class="form-reply"></textarea>
</div>
<div class="reply-button">
<input id="inputbutton" type="submit" value="&#10148;" class="btn btn-default"/> <input id="inputbutton" type="submit" value="&#10148;" class="btn btn-default"/>
</div>
</form> </form>
</div> </div>
</div> </div>
......
...@@ -2847,6 +2847,13 @@ document.getElementById('input').onkeypress = function(e) { ...@@ -2847,6 +2847,13 @@ document.getElementById('input').onkeypress = function(e) {
} }
}; };
document.getElementById('input').oninput = function(e) {
let textarea = /** @type{HTMLTextAreaElement} */ (e.target);
e.preventDefault();
// update replicated content
textarea.parentNode.dataset.replicatedValue = textarea.value;
};
function chatResizer(e) { function chatResizer(e) {
e.preventDefault(); e.preventDefault();
let full_width = document.getElementById("mainrow").offsetWidth; let full_width = document.getElementById("mainrow").offsetWidth;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment