Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions packages/components/client/chat/input.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<template>
<div class="textarea">
<input
<div class="textarea" :data-replicated-text="text">
<textarea
autocomplete="off"
step="any"
:value="text"
:placeholder="placeholder"
@input="onInput"
@paste="onPaste"
@keydown.enter.stop="onEnter"
@keydown.enter.exact.stop.prevent="onEnter"
@keydown.shift.enter.stop.prevent="onShiftEnter"
/>
</div>
</template>
Expand Down Expand Up @@ -40,6 +41,11 @@ function onEnter() {
text.value = ''
}

function onShiftEnter() {
text.value ??= ''
text.value += '\n'
}

function onInput(event: Event) {
text.value = (event.target as HTMLInputElement).value
}
Expand Down Expand Up @@ -79,18 +85,37 @@ async function onPaste(event: ClipboardEvent) {

<style lang="scss" scoped>

input {
.textarea {
display: grid;

&::after {
// This value is required for preventing jumpy behaviour !
content: attr(data-replicated-text) ' ';
white-space: pre-wrap;
visibility: hidden;
}
}

.textarea::after,
textarea {
grid-area: 1 / 1 / 2 / 2;

padding: 0;
width: 100%;
border: none;
outline: none;
font-size: 1em;
height: inherit;
box-sizing: border-box;
}

textarea {
color: inherit;
display: inline-block;
transition: 0.3s ease;
box-sizing: border-box;
background-color: transparent;
resize: none;
overflow: hidden;
}

</style>