Skip to content

Commit 04479c9

Browse files
committed
fix reactivity
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 96052d1 commit 04479c9

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/components/Questions/AnswerInput.vue

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
class="question__item__pseudoInput" />
1212
<input
1313
ref="input"
14+
v-model="localText"
1415
:aria-label="ariaLabel"
1516
:placeholder="placeholder"
16-
:value="answer.text"
1717
class="question__input"
1818
:class="{ 'question__input--shifted': !isDropdown }"
1919
:maxlength="maxOptionLength"
@@ -175,11 +175,15 @@ export default {
175175
queue: null,
176176
debounceOnInput: null,
177177
isIMEComposing: false,
178+
localText: this.answer?.text ?? '',
178179
}
179180
},
180181
181182
computed: {
182183
canCreateLocalAnswer() {
184+
if (this.answer.local) {
185+
return !!this.localText?.trim()
186+
}
183187
return !!this.answer.text?.trim()
184188
},
185189
@@ -255,6 +259,17 @@ export default {
255259
},
256260
},
257261
262+
watch: {
263+
// Keep localText in sync when the parent replaces/updates the answer prop
264+
answer: {
265+
handler(newVal) {
266+
this.localText = newVal?.text ?? ''
267+
},
268+
269+
deep: true,
270+
},
271+
},
272+
258273
created() {
259274
this.queue = new PQueue({ concurrency: 1 })
260275
@@ -283,7 +298,7 @@ export default {
283298
*/
284299
async onInput({ target, isComposing }) {
285300
if (this.answer.local) {
286-
this.$set(this.answer, 'text', target.value)
301+
this.localText = target.value
287302
return
288303
}
289304
@@ -324,7 +339,7 @@ export default {
324339
return
325340
}
326341
327-
const value = this.$refs.input?.value ?? ''
342+
const value = this.localText ?? ''
328343
if (!value.trim()) {
329344
return
330345
}
@@ -339,12 +354,15 @@ export default {
339354
// Forward changes, but use current answer.text to avoid erasing
340355
// any in-between changes while creating the answer
341356
newAnswer.text = this.$refs.input.value
357+
this.localText = ''
342358
343359
this.$emit('create-answer', this.index, newAnswer)
344360
},
345361
346362
/**
347363
* Request a new answer
364+
*
365+
* @param {Event} e the event
348366
*/
349367
focusNextInput(e) {
350368
if (this.isIMEComposing || e?.isComposing) {

0 commit comments

Comments
 (0)