Repository navigation
feat: add Rotate plugin - #469
Merged
Merged
Conversation
Add a Rotate plugin that lets users fix images with incorrect orientation via clockwise and counterclockwise toolbar buttons (configurable via `rotate.buttons`). Each image keeps its rotation while the lightbox is open, including when navigating away and back or when slides are added or removed. Rotated images fit the slide area and work with the Zoom and Thumbnails plugins regardless of plugin order. The plugin also supports an initial `slide.rotation`, an `on.rotate` callback, a `rotate.ref` for programmatic control, and custom icons and controls via `render`. Custom slide renderers can read the rotation with the `useSlideRotation` hook and pass it to `ImageSlide`. Co-authored-by: Callum John Spiller <callumjohnspiller@gmail.com>
Closed
commit: |
Closed
callumjohnspiller
approved these changes
Oct 20, 2026
callumjohnspiller
left a comment
Contributor
There was a problem hiding this comment.
This is really cool - definitely a vast improvement on my original PR!
With the Inline plugin, the lightbox never closes, so user rotations last until the lightbox unmounts.
…-back Calling `rotateClockwise()` or `rotateCounterClockwise()` more than once before the lightbox re-rendered (e.g., twice in the same event handler to rotate by 180 degrees) applied only the last call, and `on.rotate` reported the same stale angle for each call. Each call now builds on the rotation set by the previous one.
The assertion hard-coded `0px` because jsdom reports a zero slide height. Compute the expected `maxWidth` from the slide rect passed to `render.slide` instead, so the test keeps passing when the test setup mocks a non-zero container height.
igordanchenko
force-pushed
the
feat/rotate-plugin
branch
from
October 27, 2026 18:24
5ad8276 to
05bd729
Compare
Add tests for rotated cover images sized to the transposed slide rect, max zoom computed from transposed image dimensions, zoom reset on rotation, and `ResponsiveImage` sizing and source selection for rotated and zoomed images. Mock `clientHeight` for `.yarl__container` in the test setup, so that the slide rect has a non-zero height in jsdom.
The `normalizeRotation` tests in `utils.spec.ts` already cover the edge cases. The hook test now only checks that the provided rotation is normalized.
…oads On the first rotation, images with `srcSet` briefly shrank and then expanded once the browser loaded the larger source picked for the rotated layout, which showed as a flicker on fast networks and a visible jump on slow ones. Rotated images now fit the slide right away.
Owner
Author
|
@callumjohnspiller, I'm finalizing the implementation and would appreciate it if you could take another look. You can install the latest preview build with |
igordanchenko
force-pushed
the
feat/rotate-plugin
branch
from
October 28, 2026 00:12
dae4147 to
a40e084
Compare
|
🎉 This PR is included in version 3.33.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a Rotate plugin that lets users fix images with incorrect orientation. This feature has been requested a number of times over the years (see #100 and #348).
Supersedes #467. Thanks, @callumjohnspiller, for the initial implementation that got this moving!
Rotate plugin
rotate.buttons:"both"by default,"clockwise"or"counterclockwise")rotate.reffor programmatic control (rotation,disabled,rotateClockwise,rotateCounterClockwise)on.rotatecallback, which apps can use to persist user rotations, together with the initialslide.rotationrender.iconRotateClockwise,render.iconRotateCounterClockwiseandrender.buttonRotate, and theRotate clockwise/Rotate counterclockwiselabelssrc, so it persists across navigation and slides changes while the lightbox is open (with the Inline plugin, until the lightbox unmounts)Core
useSlideRotationhook andSlideRotationContext, which return0unless the Rotate plugin is installedrotationprop onImageSlide, which fits quarter-turn rotations into the slidenormalizeRotationutilityWithout the Rotate plugin, the lightbox behaves exactly as before.
Compatibility
imageFitmodes (containandcover) in landscape and portrait viewportsrender.slide/render.thumbnailfunctions opt in via theuseSlideRotationhook (documented, including anext/imageexample)rotateproperty (Chrome/Edge 104+, Safari 14.1+, Firefox 72+)Docs
docs/plugins/rotate.md), including persisting rotation between sessions, custom slides, and a live demo and sandboxdocs/examples/nextjs.md)README.mdanddocs/plugins.mdTesting
useSlideRotationhook andnormalizeRotation, including Zoom integration (maximum zoom for rotated images, zoom reset on rotation, responsive image sizing and source selection) and rotated image sizing in bothimageFitmodesRelated issue
Closes #468