Skip to content

Commit bcbf02b

Browse files
committed
fix: Replace NcRichContenteditable with textarea
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
1 parent ec9ebc2 commit bcbf02b

2 files changed

Lines changed: 40 additions & 16 deletions

File tree

src/components/Questions/Question.vue

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@
7575
</NcActions>
7676
</div>
7777
<div v-if="hasDescription || edit || !questionValid" class="question__header__description">
78-
<NcRichContenteditable v-if="edit || !questionValid"
79-
:multiline="true"
78+
<textarea v-if="edit || !questionValid"
79+
ref="description"
8080
:value="description"
8181
:placeholder="t('forms', 'Description (formatting using Markdown is supported)')"
8282
:maxlength="maxStringLengths.questionDescription"
8383
class="question__header__description__input"
84-
@update:value="onDescriptionChange" />
84+
@input="onDescriptionChange" />
8585
<!-- eslint-disable-next-line vue/no-v-html -->
8686
<div v-else class="question__header__description__output" v-html="computedDescription" />
8787
</div>
@@ -98,7 +98,6 @@ import { directive as ClickOutside } from 'v-click-outside'
9898
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
9999
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
100100
import NcActionCheckbox from '@nextcloud/vue/dist/Components/NcActionCheckbox.js'
101-
import NcRichContenteditable from '@nextcloud/vue/dist/Components/NcRichContenteditable.js'
102101
103102
import IconAlertCircleOutline from 'vue-material-design-icons/AlertCircleOutline.vue'
104103
import IconDelete from 'vue-material-design-icons/Delete.vue'
@@ -118,7 +117,6 @@ export default {
118117
NcActions,
119118
NcActionButton,
120119
NcActionCheckbox,
121-
NcRichContenteditable,
122120
},
123121
124122
inject: ['$markdownit'],
@@ -204,20 +202,36 @@ export default {
204202
return this.description !== ''
205203
},
206204
},
205+
watch: {
206+
edit(newEdit) {
207+
if (newEdit || !this.questionValid) {
208+
this.resizeDescription()
209+
}
210+
},
211+
},
207212
208213
methods: {
209214
onTitleChange({ target }) {
210215
this.$emit('update:text', target.value)
211216
},
212217
213-
onDescriptionChange(value) {
214-
this.$emit('update:description', value)
218+
onDescriptionChange({ target }) {
219+
this.resizeTextarea()
220+
this.$emit('update:description', target.value)
215221
},
216222
217223
onRequiredChange(isRequired) {
218224
this.$emit('update:isRequired', isRequired)
219225
},
220226
227+
resizeDescription() {
228+
// next tick ensures that the textarea is attached to DOM
229+
this.$nextTick(() => {
230+
const rows = this.$refs.description.value.split('\n').length
231+
this.$refs.description.setAttribute('rows', rows)
232+
})
233+
},
234+
221235
/**
222236
* Enable the edit mode
223237
*/
@@ -349,6 +363,7 @@ export default {
349363
position: relative;
350364
left: -12px;
351365
padding: 4px 10px;
366+
resize: none;
352367
}
353368
354369
&__input,

src/views/Create.vue

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
<label class="hidden-visually" for="form-desc">
5959
{{ t('forms', 'Description') }}
6060
</label>
61-
<NcRichContenteditable id="form-desc"
61+
<textarea id="form-desc"
62+
ref="description"
6263
class="form-desc form-desc__input"
6364
:value="form.description"
64-
:multiline="true"
6565
:placeholder="t('forms', 'Description (formatting using Markdown is supported)')"
6666
:maxlength="maxStringLengths.formDescription"
67-
@update:value="updateDescription" />
67+
@input="updateDescription" />
6868
</template>
6969
<!-- eslint-disable-next-line vue/no-v-html -->
7070
<div v-else class="form-desc form-desc__output" v-html="formDescription" />
@@ -142,7 +142,6 @@ import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
142142
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent.js'
143143
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
144144
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
145-
import NcRichContenteditable from '@nextcloud/vue/dist/Components/NcRichContenteditable.js'
146145
import IconPlus from 'vue-material-design-icons/Plus.vue'
147146
148147
import answerTypes from '../models/AnswerTypes.js'
@@ -168,7 +167,6 @@ export default {
168167
NcAppContent,
169168
NcEmptyContent,
170169
NcLoadingIcon,
171-
NcRichContenteditable,
172170
Question,
173171
QuestionLong,
174172
QuestionShort,
@@ -284,24 +282,34 @@ export default {
284282
285283
enableEdit() {
286284
this.edit = true
285+
this.resizeDescription()
287286
},
288287
289288
initEdit() {
290289
if (this.form.title) {
291290
this.edit = false
292291
} else {
293292
this.edit = true
293+
this.resizeDescription()
294294
}
295295
},
296296
297+
resizeDescription() {
298+
// nextTick to ensure textarea is attached to DOM
299+
this.$nextTick(() => {
300+
const rows = this.$refs.description.value.split('\n').length
301+
this.$refs.description.setAttribute('rows', rows)
302+
})
303+
},
304+
297305
/**
298306
* Update the description
299307
*
300-
* @param {string} value New description
308+
* @param {InputEvent} ev The input event of the textarea
301309
*/
302-
updateDescription(value = '') {
303-
// We need this for nextcloud/nextcloud-vue#3669
304-
this.form.description = value.trimEnd()
310+
updateDescription({ target }) {
311+
this.form.description = target.value
312+
this.resizeDescription()
305313
this.saveDescription()
306314
},
307315
@@ -485,6 +493,7 @@ export default {
485493
486494
&__input {
487495
padding: 3px 14px 18px; // 2px smaller because of border
496+
resize: none;
488497
}
489498
490499
// Styling for rendered Output

0 commit comments

Comments
 (0)