Skip to content

Commit

Permalink
feat: autosize the input field in translate dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Jun 14, 2023
1 parent 08863e6 commit 809765e
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/components/Modal/Translate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
input-id="fromLanguage"
:placeholder="t('text', 'Select language')"
:options="fromLanguages"
:disabled="disableFromLanguage"
:disabled="disableFromLanguageSelect"
:append-to-body="false" />
</div>
<textarea ref="input"
v-model="input"
autofocus="true"
@focus="disableFromLanguage = false" />
@input="autosize"
@focus="onInputFocus" />
</div>
<div class="col">
<div class="language-selector">
Expand All @@ -50,7 +51,10 @@
:disabled="!fromLanguage"
:append-to-body="false" />
</div>
<textarea v-model="result" readonly :class="{'icon-loading': loading }" />
<textarea ref="result"
v-model="result"
readonly
:class="{'icon-loading': loading }" />
</div>
</div>
<div class="translate-actions">
Expand Down Expand Up @@ -107,7 +111,7 @@ export default {
canDetect: loadState('text', 'translation_can_detect'),
loading: false,
error: null,
disableFromLanguage: true,
disableFromLanguageSelect: true,
}
},
computed: {
Expand Down Expand Up @@ -186,6 +190,15 @@ export default {
async contentReplace() {
this.$emit('replace-content', this.result)
},
autosize() {
this.$refs.input.style.height = 'auto'
this.$refs.input.style.height = this.$refs.input.scrollHeight + 'px'
this.$refs.result.style.height = this.$refs.input.scrollHeight + 'px'
},
onInputFocus() {
this.disableFromLanguageSelect = false
this.autosize()
},
},
}
</script>
Expand All @@ -209,7 +222,10 @@ textarea {
display: block;
width: 100%;
margin-bottom: 12px;

height: auto;
resize: none;
box-sizing: border-box;
overflow: hidden;
}

.language-selector {
Expand Down

0 comments on commit 809765e

Please sign in to comment.