mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-07-05 11:00:50 +00:00
chat-input now resizes automatically when typing
This commit is contained in:
parent
a27b269d7c
commit
66fed0d97a
1 changed files with 31 additions and 2 deletions
|
|
@ -19,7 +19,17 @@
|
||||||
<news v-else />
|
<news v-else />
|
||||||
<div class="chat-input-area" v-if="selectedChannelID">
|
<div class="chat-input-area" v-if="selectedChannelID">
|
||||||
<div class="message-area">
|
<div class="message-area">
|
||||||
<textarea class="chat-input" ref="input-box" placeholder="Message" @keydown="chatInput" @input="onInput" v-model="message"></textarea>
|
<textarea
|
||||||
|
rows="1"
|
||||||
|
class="chat-input"
|
||||||
|
ref="input-box"
|
||||||
|
placeholder="Message"
|
||||||
|
@keydown="chatInput"
|
||||||
|
@keyup="delayedResize"
|
||||||
|
@change="resize"
|
||||||
|
@input="onInput"
|
||||||
|
v-model="message"
|
||||||
|
></textarea>
|
||||||
<button :class="{'send-button': true, 'error-send-button': messageLength > 5000}" @click="sendMessage">Send</button>
|
<button :class="{'send-button': true, 'error-send-button': messageLength > 5000}" @click="sendMessage">Send</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="info">
|
<div class="info">
|
||||||
|
|
@ -131,16 +141,32 @@ export default {
|
||||||
await typingService.post(this.selectedChannelID);
|
await typingService.post(this.selectedChannelID);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
},
|
},
|
||||||
|
resize(event) {
|
||||||
|
let input = this.$refs["input-box"]
|
||||||
|
|
||||||
|
if(input.scrollHeight < 50) {
|
||||||
|
input.style.height = '1em'
|
||||||
|
} else {
|
||||||
|
input.style.height = 'auto';
|
||||||
|
input.style.height = `calc(${input.scrollHeight}px - 1em)`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
delayedResize(event) {
|
||||||
|
this.resize(event)
|
||||||
|
},
|
||||||
async onInput(event){
|
async onInput(event){
|
||||||
|
this.delayedResize(event)
|
||||||
|
|
||||||
this.messageLength = this.message.length;
|
this.messageLength = this.message.length;
|
||||||
const value = event.target.value.trim();
|
const value = event.target.value.trim();
|
||||||
if (value && this.postTimerID == null) {
|
if (value && this.postTimerID == null) {
|
||||||
// Post typing status
|
|
||||||
this.postTimer()
|
this.postTimer()
|
||||||
await typingService.post(this.selectedChannelID);
|
await typingService.post(this.selectedChannelID);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
chatInput(event) {
|
chatInput(event) {
|
||||||
|
this.delayedResize(event)
|
||||||
|
|
||||||
// when enter is press
|
// when enter is press
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
// and the shift key is not held
|
// and the shift key is not held
|
||||||
|
|
@ -316,6 +342,9 @@ export default {
|
||||||
outline: none;
|
outline: none;
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
transition: 0.3s;
|
transition: 0.3s;
|
||||||
|
height: 1em;
|
||||||
|
overflow: hidden;
|
||||||
|
max-height: 30vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-input:hover{
|
.chat-input:hover{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue