Skip to content

Image crop

Pro

Frames a photo before upload: drag, pinch or zoom it behind a fixed frame, and get the crop in the original pixels. Not an M3 component (@windmorph/react-pro).

import { ImageCropDialog, ImageCropper } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Keyboard

Image crop keyboard
KeyAction
TabMoves between the dialog's buttons and, in the cropper, the photo area, Zoom out, the zoom slider and Zoom in.
Arrow Up or Arrow Down or Arrow Left or Arrow RightMove the photo 10px that way, or 50px with Shift. It stops where it would leave a gap in the frame.On the photo area
+ or -Zoom in by 10%, or back out by the same step (= and _ work too).On the photo area
0Resets the photo to fill the frame, centred.On the photo area
Arrow Left or Arrow RightChange the zoom, as on any Slider.On the zoom slider
EscapeCloses the dialog, except while pending.In the dialog

The arrow keys move the photo the way they point in every layout direction.

Screen reader

Role
In the dialog, a dialog named by its title. Inside, the photo area is a group, the zoom control a slider, and Zoom out and Zoom in are buttons.
Accessible name
The photo area is named by labels.area ("Photo position") and described by labels.instructions, which say how to move and zoom from the keyboard. The slider is named by labels.zoom and the buttons by labels.zoomOut and labels.zoomIn.
States announced
The slider reads its value as a percentage ("150%"). Zoom out and Zoom in are disabled at their limits, and Save until the photo is ready.
  • The photo itself is decorative (alt=""); the frame and the circle guide are hidden from assistive tech.
  • A photo that can't be opened (HEIC in some browsers, or a file that isn't an image) shows labels.error in an alert region that goes into the page before the message, so it is announced, and Save stays disabled.
  • The zoom buttons show their names as tooltips through the icon button, without reading them twice.
  • While pending, a progress bar named by labels.pending shows, Save is pending (it keeps focus and its name adds labels.pending: "Save, Uploading"), Cancel is disabled, and the dialog can't be dismissed.

Focus

  • The photo area joins the Tab order once the photo has loaded, and shows M3's focus indicator on keyboard focus: a 3px secondary outline 2px outside it.
  • When Zoom out or Zoom in reaches its limit and turns itself off, focus moves to the other zoom button (or the photo area) instead of dropping to the page.
  • Pressing Save keeps focus on it while the app saves.
  • The dialog moves focus to its first interactive element when it opens, keeps focus inside, and returns it to what opened it when it closes, as any Dialog does.

Touch target

  • The photo area spans the cropper's full width, with 24px around the frame.
  • Zoom out and Zoom in are small icon buttons (40px) with an invisible 48 × 48px touch target.
  • Dragging is never required: the zoom slider and buttons zoom, and the arrow keys move the photo (WCAG 2.2, 2.5.7). A pointer drags the photo, two fingers pinch to zoom, and Ctrl or ⌘ with the wheel (or a trackpad pinch) zooms around the pointer; a plain wheel scrolls the page.
  • Inline, a vertical swipe over the photo scrolls the page while the photo has nothing to move vertically (a landscape photo at zoom 1), so the cropper never traps a touch screen. A portrait photo, or one zoomed in, takes the swipe to move. Inside the dialog every gesture moves the photo.

Motion

  • Resetting with 0 eases the photo back on the M3 effects spring, which never uncovers the frame; under reduced motion it jumps there. Dragging, pinching and the wheel follow the pointer without easing.
  • The dialog opens and closes with the Dialog motion.

What you need to do

  • Pass labels from your translations, including instructions, the only place the keyboard controls are explained.
  • Keep the dialog open while you upload (pending, with progress when you know it), and close it yourself when the upload ends.
  • Offer a file type the browser can show (JPEG or PNG): pick files with accept on a FileTrigger, and expect the error for others.
  • In forced-colours mode the frame edge and the circle guide use the system text colour and the photo around the frame stays dimmed but visible; keep classNames overrides from removing them.
  • Give a custom zoomInIcon or zoomOutIcon no name of its own: the button is named by labels.