-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathQuestionLong.vue
More file actions
109 lines (99 loc) · 2.15 KB
/
QuestionLong.vue
File metadata and controls
109 lines (99 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!--
- SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<Question
v-bind="questionProps"
:title-placeholder="answerType.titlePlaceholder"
:warning-invalid="answerType.warningInvalid"
v-on="commonListeners">
<div class="question__content">
<textarea
ref="textarea"
:aria-label="
t(
'forms',
'A long answer for the question “{text}”',
{
text,
},
undefined,
{ escape: false },
)
"
:placeholder="submissionInputPlaceholder"
:disabled="!readOnly"
:required="isRequired"
:value="values[0]"
dir="auto"
class="question__text"
:maxlength="maxStringLengths.answerText"
minlength="1"
:name="name || undefined"
@input="onInput"
@keypress="autoSizeText"
@keydown.ctrl.enter="onKeydownCtrlEnter" />
</div>
</Question>
</template>
<script>
import QuestionMixin from '../../mixins/QuestionMixin.js'
export default {
name: 'QuestionLong',
mixins: [QuestionMixin],
data() {
return {
height: 1,
}
},
computed: {
submissionInputPlaceholder() {
if (this.readOnly) {
return this.answerType.submitPlaceholder
}
return this.answerType.createPlaceholder
},
},
watch: {
values: {
handler() {
this.$nextTick(() => {
this.autoSizeText()
})
},
immediate: true,
},
},
methods: {
onInput() {
const textarea = this.$refs.textarea
this.$emit('update:values', [textarea.value])
},
autoSizeText() {
const textarea = this.$refs.textarea
if (!textarea) {
return
}
textarea.style.cssText = 'height:auto; padding:0'
textarea.style.cssText = `height: ${textarea.scrollHeight + 28}px`
},
onKeydownCtrlEnter(event) {
this.$emit('keydown', event)
},
},
}
</script>
<style lang="scss" scoped>
.question__text {
width: 100%;
resize: none;
&:disabled {
// Just overrides Server CSS-Styling for disabled inputs. -> Not Good??
background-color: var(--color-main-background);
color: var(--color-main-text);
width: calc(100% - var(--default-clickable-area)) !important;
margin-inline-start: -12px;
}
}
</style>