kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

[HTML5 Article Renderer] Fix image rendering and migrate the lightbox to the Composition API

Open akolson opened this issue 1 year ago • 4 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Lightbox.vue is Options API and predates the setup() standard. Migrate it to the Composition API, then fix image rendering: images overflow their wrapper and paint over the text beneath them (#14110), and the expand button is mouse-only, appears on every image whether or not expanding reveals anything more, and at a fixed 40px covers small images entirely.

Complexity: Medium Target branch: develop

Context

Lightbox.vue (~475 lines, Options API) owns dialog lifecycle, zoom, pan, keyboard handling, size calculation, and the dialog-polyfill / closedby fallbacks. Image sizing and the button that opens the lightbox live in SafeHtmlImage.vue and style.scss.

Images overflow their wrapper. Three height caps compete: .image-container at max-height: 80vh, .img-wrapper at max-height: 584px, and img.safe-html at max-height: 80vh. The image obeys its own cap rather than the wrapper's, so whenever 80vh exceeds 584px — a window taller than roughly 730px — the image is larger than the wrapper holding it, and nothing clips it or reserves the space. At 1280×900 the wrapper measures 584px and the image 689px, and the 105px difference covers the heading and the first line of the paragraph below:

Image overlapping the text beneath it

At a 700px window height both measure 560px and nothing overlaps, which is why #14110 was reported against Chrome, Firefox and Safari but not Edge — window height, not engine. The 584px cap has no basis in the design spec.

The two caps could disagree because .img-wrapper is styled from two files: style.scss sets its position, display and hover shadow, SafeHtmlImage.vue sets its max-width and max-height. .image-container, img.safe-html and .expand-btn are in style.scss as well, while .img-button and .expand-btn-transition are in the component.

The expand button:

  • .expand-btn is opacity: 0, revealed by .img-wrapper:hover or .expand-btn:focus. Touch devices have no hover, so it never appears; tapping the image opens the lightbox with nothing to signal that it will.

  • It renders on every image, including images displayed at natural size, where expanding reveals nothing further.

  • It is a fixed 40×40 whatever the image measures. On a 100px image the button and its tooltip cover the image:

    Expand button covering a 100px image

Lightbox interaction is mouse-only — mousedown/mousemove/mouseup for pan, wheel for zoom. There are no touch or pointer handlers, so there is no pinch-zoom, and panning on touch relies on the browser emulating mouse events from a drag.

browserslist-config-kolibri floors at Firefox 52 / Safari 11.1 / iOS 10, below <dialog> support (Firefox 98 / Safari 15.4), so dialog-polyfill and the closedby fallback are still required.

The Change

Migrate Lightbox.vue to the Composition API. Behaviour is unchanged by the migration: Lightbox.spec.js passes without edits.

Then:

  • Images are capped, never stretched: centred, aspect ratio preserved, no wider than the smaller of 900px and the container, no taller than 80vh, with a 1px fineLine border. An image smaller than that renders at its natural size.
  • A single maximum height governs the image and its wrapper together, so an image never exceeds the box holding it at any window size.
  • Image styles move into SafeHtmlImage.vue, as table styles did in 4e07cee9e7e8fa3c36cbe9bb644e7db6fe6bf102: .image-container, .img-wrapper, img.safe-html, .expand-btn and its hover and focus rules.
  • Pinch to zoom the expanded image between the same 1× and 4× bounds the zoom buttons use, and pan it with a single finger, clamped by the same limits as mouse drag so the image cannot be dragged out of view.
  • The expand button is at least 44×44, meeting the WCAG target size minimum.
  • No expand button on an image that renders under 100px in either dimension, or on one that is not being displayed smaller than its natural size — expanding it would show no more.
  • Because width/height are stripped, rendered size is only known once the image loads, and the 80vh cap means it changes with the viewport. Both conditions are re-checked on load and on resize.
  • The image is no longer wrapped in a button. A single overlay control covers it, carrying the click target, the tab stop, the expand icon and the hover shadow. The image itself is never focusable.
  • That control takes its display from an inherited custom property: display: var(--content-affordance-display, block).
  • Any container suppresses the control by setting --content-affordance-display: none. display: none removes it from the tab order and the accessibility tree. No JavaScript is involved.
  • draggable.scss sets that property on .draggable-item, so an image inside a dragged card has no expand control, no hover shadow and no tab stop.
  • Where the control is present, it still appears on hover and focus only, and clicking or tapping the image still opens the lightbox.

Out of Scope

  • The four-composable, three-component split this issue previously specified.
  • Removing dialog-polyfill or the closedby fallback — the browser floor still needs both.
  • Honouring width/height on images; they stay stripped.

Acceptance Criteria

General

  • [ ] Lightbox.vue uses setup(), with no Options API blocks remaining.
  • [ ] At any window height, no image overlaps the content beneath it, and wrapper and image report the same rendered height.
  • [ ] An image whose natural size is smaller than the container renders at that natural size, not stretched to fill it.
  • [ ] At a 400px-wide viewport an image scales down to the container width, with no horizontal page overflow.
  • [ ] No image rules remain in style.scss; the bare element rules stay there.
  • [ ] Pinching the expanded image zooms it between 1× and 4×.
  • [ ] A single-finger drag pans the expanded image, clamped so it cannot be moved out of view.
  • [ ] Images rendering under 100px in either dimension have no expand button.
  • [ ] Images not displayed smaller than their natural size have no expand button.
  • [ ] Resizing the window adds or removes the button as images cross those thresholds.
  • [ ] Clicking or tapping an image opens the lightbox wherever the expand control is present.
  • [ ] No image is focusable; where expanding is available, one overlay control carries the click target and the expand icon.
  • [ ] An image inside a .draggable-item shows no expand control, no hover shadow, and puts nothing in the tab order.
  • [ ] Clicking an image inside a .draggable-item does nothing.
  • [ ] A QTI order interaction whose choices contain images reorders by drag and by keyboard.

Accessibility

  • [ ] The expand button is at least 44×44.
  • [ ] Where the button is present, focus returns to it when the lightbox closes.

Testing

  • [ ] Existing cases in Lightbox.spec.js pass without modification.
  • [ ] Tests cover both conditions under which the button is absent.
  • [ ] A test asserts the image is not rendered inside a button.

References

  • Image spec: maintain aspect ratio, centre-aligned, max-width: 900px, height: auto, max-height: 80vh, 1px tokens.fineLine stroke. Figma
  • Today's responsive scaling comes from img.safe-html { max-width: 100% } inside the 900px-capped wrapper, not from the 900px value alone.
  • The overflow is reported in #14110.
  • The hover-reveal and the width/height strip both arrived in 763f3cd5e74cf120767d6710f9ec4afb2f939485.
  • Lightbox a11y behaviour was specified in #13546.
  • Browser floor: packages/browserslist-config-kolibri/index.js.
  • The suppression property is set on .draggable-item in packages/kolibri-common/components/draggable/draggable.scss; the class comes from DraggableItem.vue.
  • First context needing it: OrderInteraction.vue, whose choices are dragged as cards and can contain images.
  • Inherited custom properties with a var() fallback are used already: --table-focus-outline in SafeHtmlTable.vue, --qti-choice-color-primary in ChoiceInteraction.vue.

AI usage

Claude drafted this issue while checking the HTML5 renderer's sub-issues against the code and a running dev server. It reproduced the #14110 overflow, measured it at two window heights, and traced it to the competing height caps; it also confirmed the hover-reveal, the fixed button size, and the absence of touch handlers, and produced both screenshots. I supplied the image spec from Figma, set the 44px and 100px thresholds, decided the tap behaviour, and ruled out upscaling small images; I dropped the component-split scope this issue previously carried. Claude proposed a provide/inject mechanism for suppressing the expand control; I rejected it as too bound to the draggable implementation and asked for a CSS property instead, which is what the issue now specifies.

akolson avatar Oct 22 '25 13:10 akolson

Brainstormed #13854 against the code. The spec holds up — one fork I can't resolve from the issue or the codebase, plus four assumptions I'll take unless corrected.

Open question: how wide is the .draggable-item suppression meant to be?

.draggable-item is applied in four places, not one:

Consumer Contains SafeHTML images?
OrderInteraction.vue (QTI) yes — the intended target
QuestionsAccordion.vue (coach) yes — wraps a full ContentViewer per question
LessonResourcesTable.vue no
SectionOrder.vue no

QuestionsAccordion renders DraggableItem around every question regardless of isSortable, and a QTI question body reaches SafeHtmlImage via AssessmentItem → SafeHTML. So a --content-affordance-display: none rule in draggable.scss also removes image expansion from coach quiz-question previews, sortable or not — a surface no acceptance criterion covers, so neither review nor QA would catch it.

Also worth noting: OrderInteraction drags by a DraggableHandle, not by the card body, so there is no click conflict between the expand control and dragging.

Which do you want?

  • A — blanket, as written: draggable.scss on .draggable-item. Accepts the coach change.
  • B — scoped: OrderInteraction.vue sets it on the choice card. Same CSS mechanism, no reach into coach.

Assumptions I'll proceed on

  1. The control stays hover/focus-only. The Overview lists "the expand button is mouse-only" as a defect, but The Change says it "still appears on hover and focus only". Reading the later text as governing: the touch fix is that the whole image becomes a real click target, not that the chip shows on touch.
  2. "At least 44×44" is measured on the visible chip. The overlay button is ≥100px by construction, so the AC only bites on the chip. And since "a single overlay control" carries the tab stop, the chip becomes a KIcon in a styled span — KIconButton can't nest inside the overlay button.
  3. Pinch is continuous within [1, 4], not snapped to the buttons' 0.25 step. Touch Events, not Pointer Events — the browserslist floor is below Pointer Event support.
  4. The 80vh cap goes on the image alone, and both wrapper caps are deleted. max-height: 100% on the image can't work: a percentage max-height against a parent that only sets max-height computes to none, which is how the two caps diverged.

One consequence to flag

The two suppression rules are an OR, so an image with a large natural size rendered under 100px — a diagram in a narrow choice card — gets no expand control, and with no control there is no click target either. That is the case where expanding helps most. Following the issue as written; say if the 100px rule should yield to "displayed smaller than natural".

Verification

Three criteria can't be unit-tested — jsdom has no layout and resolves neither the global stylesheet nor the custom-property cascade. The .draggable-item suppression, the #14110 overflow at 1280×900, and pinch/pan all need live browser QA.

rtibblesbot avatar Aug 14 '26 22:08 rtibblesbot

The 100px rule is primarily because the button has to be a minimum of 44px x 44px, so if it's a 100px, the button mostly obscures the image and gives a weird user experience.

For the QuestionsAccordion - I feel like that's an issue with the draggable target - the drag and drop is only for the question item, the fact that it encloses the entire content viewer as well is an accident of the accordion item being open at the same time. I would prefer to have the rule apply as a blanket, and we find a way to make it clear that the accordion content is not a child of the draggable item.

rtibbles avatar Aug 15 '26 00:08 rtibbles

Answered — design settled. Blanket rule, and here is the way to exempt the accordion content.

Accordion exemption

The content has to stay a DOM child of the drag item: SortableJS reorders the region's direct children, and the header and content must move together when a question is reordered. So the exemption is declared, not restructured.

AccordionItem.vue's .content wrapper sets --content-affordance-display: initial. initial on an unregistered custom property makes var(--content-affordance-display, block) fall back to block, so the default is not repeated in a second file.

On AccordionItem rather than QuestionsAccordion — the invariant is the accordion's, its content is never drag content, and it holds for every consumer. Scoped styles are fine here; custom properties inherit through the cascade, not the scope attribute.

New criterion: an image inside expanded accordion content keeps its expand control, even though the accordion item is a .draggable-item.

If you would rather fix the draggable target properly in QuestionsAccordion, that is a separate change to coach's accordion and I would split it out.

Rest of the design

  • Lightbox — straight port. this._isDestroyed in enableTransitionsAfterPaint becomes a local ref set in onBeforeUnmount; commonCoreStrings stays a mixin. Lightbox.spec.js unedited is the migration's only proof.
  • Height caps — cap the image alone at 80vh and delete both wrapper caps. max-height: 100% on the image cannot substitute: a percentage max-height against a parent that only sets max-height computes to none, which is how the two caps diverged.
  • Expand control — <img> plus a sibling <button class="expand-overlay"> at inset: 0, opacity: 0, revealed on hover/focus, hover shadow moved onto it. The chip inside is a KIcon in a styled ≥44×44 span; KIconButton cannot nest inside the overlay button. v-if on width >= 100 && height >= 100 && (round(width) < naturalWidth || round(height) < naturalHeight), recomputed on load and resize — rounded rather than epsilon-tuned, since layout returns fractional CSS px against integer natural px.
  • Touch — Touch Events, not Pointer Events; the browserslist floor is below Pointer Event support. Pinch is continuous within [1, 4] reusing getDeltaLimits/clampDelta; one finger reuses the mouse delta maths. The zoom buttons stay the single-pointer alternative, so WCAG 2.5.1 holds.

Verification

Jest covers both suppression conditions, the resize transition, and that the image has no <button> ancestor, stubbing naturalWidth/getBoundingClientRect as Lightbox.spec.js already does.

Live browser QA covers what jsdom cannot resolve: the .draggable-item suppression and the accordion exemption, the #14110 overflow at 1280×900, and pinch/pan.

rtibblesbot avatar Aug 15 '26 00:08 rtibblesbot

Plan: Port Lightbox.vue to the Composition API, then fix SafeHTML image rendering — the #14110 overflow, the mouse-only expand button, and the missing touch gestures.

  • [ ] Port Lightbox.vue to the Composition API
  • [ ] Pinch-zoom and single-finger pan in the lightbox
  • [ ] Move the layout styles into SafeHtmlImage.vue and fix the height caps
  • [ ] Replace the image-in-a-button with a single overlay control
  • [ ] Render the overlay only when expanding shows more
  • [ ] Suppress the control inside draggable items, and exempt accordion content
  • [ ] Self-review the produced code

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Aug 15 '26 00:08 rtibblesbot