@@ -29,6 +29,11 @@ import { IconName } from '../../Icon';
2929
3030import styles from './cropper.module.scss' ;
3131
32+ // Zoom is incremented by ZOOM_STEP (0.1), so repeated additions accumulate
33+ // float error 1 -> 1.1 -> 1.21 -> 1.331. Rounding to one decimal is
34+ // lossless for all valid zoom values and keeps the displayed value clean.
35+ const roundZoom = ( z : number ) : number => Math . round ( z * 10 ) / 10 ;
36+
3237const EasyCrop = forwardRef < EasyCropHandle , EasyCropProps > ( ( props , ref ) => {
3338 const {
3439 aspect,
@@ -189,7 +194,7 @@ const EasyCrop = forwardRef<EasyCropHandle, EasyCropProps>((props, ref) => {
189194 onClick = { ( ) => {
190195 setRotateButtonDirection ( '' ) ;
191196 setZoomButtonDirection ( 'out' ) ;
192- setZoomVal ( zoomVal - ZOOM_STEP ) ;
197+ setZoomVal ( roundZoom ( zoomVal - ZOOM_STEP ) ) ;
193198 } }
194199 shape = { ButtonShape . Round }
195200 size = { ButtonSize . Small }
@@ -207,7 +212,7 @@ const EasyCrop = forwardRef<EasyCropHandle, EasyCropProps>((props, ref) => {
207212 zoomVal < Number ( value )
208213 ? setZoomButtonDirection ( 'in' )
209214 : setZoomButtonDirection ( 'out' ) ;
210- setZoomVal ( Number ( value ) ) ;
215+ setZoomVal ( roundZoom ( Number ( value ) ) ) ;
211216 } }
212217 hideMax
213218 hideMin
@@ -228,7 +233,7 @@ const EasyCrop = forwardRef<EasyCropHandle, EasyCropProps>((props, ref) => {
228233 onClick = { ( ) => {
229234 setRotateButtonDirection ( '' ) ;
230235 setZoomButtonDirection ( 'in' ) ;
231- setZoomVal ( zoomVal + ZOOM_STEP ) ;
236+ setZoomVal ( roundZoom ( zoomVal + ZOOM_STEP ) ) ;
232237 } }
233238 shape = { ButtonShape . Round }
234239 size = { ButtonSize . Small }
0 commit comments