From 40b5dc6dbdf659db2adcfdfb139c4dd4fa06a2f9 Mon Sep 17 00:00:00 2001 From: Patricia Romaniuc Date: Fri, 19 Jun 2026 13:09:59 +0300 Subject: [PATCH] fix(drag-in-the-blank): update onChoiceDone to pass latest value from editor PIE-701 --- .../drag-in-the-blank/configure/src/choices.jsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/drag-in-the-blank/configure/src/choices.jsx b/packages/drag-in-the-blank/configure/src/choices.jsx index b8e8d60669..7b8682bcea 100644 --- a/packages/drag-in-the-blank/configure/src/choices.jsx +++ b/packages/drag-in-the-blank/configure/src/choices.jsx @@ -134,12 +134,20 @@ export class Choices extends React.Component { onChange(newChoices); }; - onChoiceDone = (choiceId) => { + onChoiceDone = (choiceId, latestValue) => { const { onChange, model } = this.props; const { choices } = model; const currentChoice = (choices || []).find((c) => c.id === choiceId); - if (!currentChoice || !choiceIsEmpty(currentChoice)) { + // model.choices[i].value can be stale when the editor's onChange did not fire for the most recent edit + // (for example, image uploads). In that case, we want to use the latest value from the editor. + const effectiveValue = latestValue !== undefined ? latestValue : currentChoice && currentChoice.value; + + if (!currentChoice || !choiceIsEmpty({ value: effectiveValue })) { + if (currentChoice && currentChoice.value !== effectiveValue) { + const newChoices = (choices || []).map((c) => (c.id === choiceId ? { ...c, value: effectiveValue } : c)); + onChange(newChoices); + } this.setState({ focusedEl: undefined }); return; } @@ -270,12 +278,12 @@ export class Choices extends React.Component { this.onChoiceChanged(choice.value, val, choice.id); }} - onDone={() => { + onDone={(val) => { if (this.preventDone) { return; } - this.onChoiceDone(choice.id); + this.onChoiceDone(choice.id, val); }} onBlur={(e) => { const inInInsertCharacter = e.relatedTarget && e.relatedTarget.closest('.insert-character-dialog');