Drag-and-drop reordering in the QTI choice and ordering editors - #6109
Conversation
From learningequality/kolibri packages/kolibri-common/components/draggable at e5eb4ddbcc85e61ec03075e1a7b7d477455c182c. Filenames and layout kept so the copy stays diffable against the source. Deviations, all module swaps: - dragSortStrings.js: createTranslator from shared/i18n - renderSlotRoot.js: shared/logging, which exposes only error() - DragSortWidget/index.vue: shared/strings/commonStrings, shared/i18n The four direction labels are copied verbatim from Kolibri's commonCoreStrings so both stay translatable in step. shared/views/draggable/ is Studio's older, unrelated system and shares three filenames with this package — hence the separate directory. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
9417a85 to
2665786
Compare
c1ce11d to
8c320a4
Compare
|
@rtibblesbot, from the screenshots you added, I can see the drag handler icon is not properly vertically aligned with the radio button and the remove button |
AlexVelezLl
left a comment
There was a problem hiding this comment.
Good implementation overall, just found a couple of minor details.
| interaction: block(CHOICE_SINGLE_SELECT_XML), | ||
| questionType: QuestionType.SINGLE_SELECT, | ||
| }); | ||
| await fireEvent.click(screen.getByRole('button', { name: moveDownName(1) })); |
There was a problem hiding this comment.
Lets use userEvent.setup() instead.
There was a problem hiding this comment.
Switched to userEvent.setup(). This PR adds two fireEvent.click calls — this one and the ordering equivalent — and both are converted; the new error-icon test below also uses userEvent. The remaining fireEvent calls in these files predate the PR, so I left them.
| interaction: blockWithDecl(ORDERING_XML, ORDERING_DECL_XML), | ||
| questionType: QuestionType.ORDERING, | ||
| }); | ||
| await fireEvent.click(screen.getByRole('button', { name: moveDownName(1) })); |
There was a problem hiding this comment.
Done, same as the choice one.
| <div | ||
| class="position-badge" | ||
| :style="{ | ||
| backgroundColor: $themePalette.green.v_100, |
There was a problem hiding this comment.
Could we use a palette.red.v_100 background if there is an error, and remove the color style, please?
There was a problem hiding this comment.
Done — red.v_100 background when the item is invalid, and the color override is gone so the badge inherits the row text colour.
| 'is-open': isChoiceOpen(choice.id), | ||
| 'small-screen': windowIsSmall, | ||
| }" | ||
| <div class="choice-group"> |
There was a problem hiding this comment.
Could we set a surface background for these choices so that it has a better constrast when dragging and hovering on top of other options?
There was a problem hiding this comment.
Done. Applied as background-color: $themeTokens.surface on .choice-border in the style block rather than inline, so the :hover rule still wins (verified in the browser: hovering a row still paints fineLine over it). Ordering rows have the same overlap problem while dragging, so .item-border gets it too.
22a65ca to
9814af0
Compare
| // `visibility` alone is not enough: a descendant can set `visibility: visible` on | ||
| // itself and stay painted over the list — KListWithOverflow does exactly that for | ||
| // the TipTap toolbar buttons. `opacity` cannot be overridden from inside. | ||
| .draggable-item--ghost { | ||
| visibility: hidden; | ||
| opacity: 0; | ||
| } |
There was a problem hiding this comment.
Could you open a PR in Kolibri to add this (and the color attribute) to its implementation?
There was a problem hiding this comment.
This account has no push access to learningequality/kolibri, so I filed learningequality/kolibri#15255 there instead — it covers both the ghost opacity and the color prop. (Its issue type is unset: UpdateIssueIssueType is denied for this account.)
| }" | ||
| > | ||
| <!-- `@click.stop` so using the handle does not open the choice for editing --> | ||
| <DraggableHandle v-if="mode === 'edit'"> |
There was a problem hiding this comment.
If shuffle is true, we should also remove the handler because it does not make sense to reorder the items.
There was a problem hiding this comment.
Done — the handle and the region's sortable now both come off isReorderable (mode === 'edit' && !state.shuffle), so shuffling drops the grip and the keyboard move buttons together.
Searched the branch for every DraggableHandle and :sortable binding: two, this editor and OrderingInteractionEditor. Changed this one only. The ordering editor's shuffle is always true and has no author toggle — its list is the answer key, which is what "Learners will see these shuffled" above it says — so dropping its handle would remove reordering outright.
The grip and chevrons take KIcon's default otherwise, which is darker than the radio and checkbox the QTI editor rows put them next to. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`.draggable-item--ghost` relied on `visibility: hidden`, which KListWithOverflow undoes for the toolbar buttons it sizes — they stayed painted over the list while the row was dragged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
DraggableRegion emits the whole reordered array; the editors reduce it to an id order so no readonly state proxy travels back into the composable and the reorder stays expressible as a permutation of what already exists. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The move-up/move-down chevrons go; DragSortWidget's own move buttons, revealed when the handle takes focus, keep reordering keyboard-operable. Delete becomes a standalone icon button, so the row no longer needs CollapsibleToolbar. Shuffled choices reach the learner in a random order, so with shuffle on the row drops its handle and the region stops sorting. DraggableRegion is keyed on the select mode: single-select renders the list as a KRadioButtonGroup and multi-select as a plain div, and SortableJS binds to that element once, on mount. The card gets a surface background so a dragged row stays opaque over the rows beneath it, and the selection control is pulled onto the row's centre line so it sits level with the handle. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Same shape as the choice editor: drag handle at the start of the row, DragSortWidget's move buttons for the keyboard, delete as a standalone icon button in place of CollapsibleToolbar. The card gets a surface background so a dragged row stays opaque over the rows beneath it. windowIsSmall was read only by the toolbar's collapse rule, so useKResponsiveWindow goes with it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The choice editor puts the error icon where the radio or checkbox would be, rather than beside it; the ordering editor's position badge turns red. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Matches the other QTI editors' row icons. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
9814af0 to
c57181b
Compare
Summary
Reordering a choice or ordering row took one chevron click per position, from a toolbar at the row's end. Both editors now reorder by dragging a handle at the row's start, backed by a copy of Kolibri's
draggablepackage asshared/views/dragSort/. The choice editor hides the handle when shuffle is on. Delete stays as its own icon button at the end, so neither editor usesCollapsibleToolbar.The copy keeps Kolibri's filenames and layout so it stays diffable. Edits to it: Studio's i18n, strings and logging; a
colorprop onDragSortWidget;opacity: 0on the dragged row's ghost, sincevisibility: hiddenalone left the TipTap toolbar painted over the list.sortablejsis new inpackage.json, at Kolibri's version.Review follow-up also lines the handle, selection control and error icon up on one 24px box, moves an invalid choice's error icon into the selection control's place and turns the invalid ordering row's badge red, drops the row icons to
grey.v_700(which is whyTextEntryEditoris in the diff), and makes a row opaque while it is dragged.References
Fixes #6106. Source:
learningequality/kolibripackages/kolibri-common/components/draggable/ate5eb4ddbcc85e61ec03075e1a7b7d477455c182c.Reviewer guidance
Open a channel for editing, go to
/channels/<channel_id>/#/qti-demo. Questions 1-2 use the choice editor, question 6 the ordering editor.Worth questioning:
DragSortWidget's two move buttons, as in Kolibri. Labelling both announces the affordance twice.shared/views/dragSort/__tests__/uses@vue/test-utils, deprecated per AGENTS.md. Copied with the package, and the only cover over the SortableJS reconciliation.setChoiceOrder/setItemOrderare asserted to emitbodyXmlbyte-identical to the equivalent chevron move.Screenshots
axe-core AA reports one violation with both editors open: contrast on the untouched
AddListItemButton.AI usage
Used Claude Code to port the package, wire both editors, and write the tests. Verified with the Jest suite,
pre-commit run --all-files, a file-for-file diff against Kolibri, and browser QA of drag, keyboard move, announcement and RTL.@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
🟡 Waiting for feedback
Last updated: 2026-09-01 13:01 UTC