Skip to content

Image Editor: Add a maxZoom option to useImageEditor - #86406

Closed
ramonjd wants to merge 2 commits into
add/image-editor-export-imagefrom
add/image-editor-max-zoom
Closed

ramonjd wants to merge 2 commits into
add/image-editor-export-imagefrom
add/image-editor-max-zoom

Conversation

@ramonjd

@ramonjd ramonjd commented Nov 6, 2026

Copy link
Copy Markdown
Member

What?

Stacked on #86405. Follow-up to #86223, part of #86145. Adds a maxZoom option to useImageEditor so a consumer can cap how far the editor zooms, below the editor's own ceiling of 10.

Why?

The rebuilt @wordpress/image-cropper keeps its old maxZoom prop with a default of 5. Clamping in the wrapper is not enough: the canvas feeds controller.maxZoom to wheel and pinch zoom, so the cap has to come from the hook.

How?

The hook validates the option (a value below 1, non-finite or above the ceiling is ignored) and reports it as controller.maxZoom, which the canvas already passes to the interaction code. setZoom and setZoomAtPoint clamp to it before dispatch. The coverage floor still wins over a cap below it, so the image keeps covering the crop. The reducer and MAX_ZOOM are unchanged, so nothing changes for the media editor.

Testing Instructions

  1. Open Storybook, "Editor/Image Editor/Canvas".
  2. Zoom with the mouse wheel or the keyboard. The canvas still reaches the same maximum as before, since no cap is set there.

Let a consumer cap how far the editor zooms. The hook clamps the zoom
the setters receive, and reports the cap as the controller's maxZoom,
which the canvas already hands to wheel and pinch zoom. The editor's
own ceiling stays the default and the upper bound; a cap below 1 or
outside the range is ignored. The coverage floor still wins over a cap
below it, so the image keeps covering the crop.
@github-actions github-actions Bot added the [Package] Image Editor Related to packages/image-editor label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@ramonjd

ramonjd commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Closing: the zoom cap only existed for the cropper rebuild, which #86417 replaces with a plain deprecation.

@ramonjd ramonjd closed this Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Image Editor Related to packages/image-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant