Skip to content

Commit c92f2ed

Browse files
author
Hector Arce De Las Heras
committed
Restoration of Original Styles Post-Zoom
This update ensures that original styles are reapplied to elements once they return to their normal size after being zoomed in. This enhancement addresses the need for maintaining visual consistency and user experience by automatically restoring the initial appearance of elements post-zoom interactions.
1 parent 2750ae4 commit c92f2ed

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/hooks/useZoomEffect/useZoomEffect.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CssProperty, changeCssProperty } from '@/utils';
88
const MAX_ZOOM = 1.25;
99
const CONDITION = true;
1010
const MEASURE_REM = 16;
11+
const INIT_ZOOM = 1;
1112

1213
const getOriginalCssProps = (element: HTMLElement, cssProps: CssProperty[]) => {
1314
// to store the original css props
@@ -48,6 +49,8 @@ export const useZoomEffect = (
4849
const originalStyles = useRef<CssProperty[]>([]);
4950
// indicate if zoomed
5051
const zoomed = useRef<boolean>(false);
52+
// control the previous zoom value
53+
const prevZoom = useRef<number>(INIT_ZOOM);
5154
// indicate the theme breakpoints
5255
const { BREAKPOINTS } = useTheme();
5356

@@ -64,10 +67,12 @@ export const useZoomEffect = (
6467
if (zoom > maxZoom) {
6568
zoomed.current && changeCssProperty(element, effect);
6669
zoomed.current = false;
67-
} else {
70+
} else if (prevZoom.current > zoom && zoom === INIT_ZOOM) {
71+
// apply the original styles when returning to normal size after zooming in
6872
!zoomed.current && changeCssProperty(element, originalStyles.current);
6973
zoomed.current = true;
7074
}
75+
prevZoom.current = zoom;
7176
}, [condition]);
7277

7378
const elementRef = useCallback(

0 commit comments

Comments
 (0)