Skip to content

Commit 445012a

Browse files
committed
refactor: change setOverflowHidden() and removeOverflowHidden() from resize-parent.js to animate.js
1 parent 3968838 commit 445012a

File tree

2 files changed

+24
-39
lines changed

2 files changed

+24
-39
lines changed

js-css-animations/animate.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ import {
99
CUSTOM_CSS_PROPERTIES,
1010
} from './globals.js';
1111

12-
import {
13-
initParentResize,
14-
endParentResize,
15-
setOverflowHidden,
16-
removeOverflowHidden,
17-
} from './resize-parent.js';
12+
import { initParentResize, endParentResize } from './resize-parent.js';
1813

1914
import {
2015
removeInlineTransition,
@@ -334,6 +329,22 @@ const enable = element => {
334329
const isEnabled = element =>
335330
!(element.getAttribute('js-anim--disabled') === 'true');
336331

332+
/**
333+
* Adds a CSS class which will set the overflow property to 'clip' (or 'hidden')
334+
* @param {HTMLElement} el - The DOM element which will receive the CSS class
335+
*/
336+
const setOverflowHidden = el => {
337+
el.classList.add(CLASS_NAMES.overflowHidden);
338+
};
339+
340+
/**
341+
* Removes the CSS class which sets the overflow property to 'clip' (or 'hidden')
342+
* @param {HTMLElement} el - The DOM element with the CSS class to remove
343+
*/
344+
const removeOverflowHidden = el => {
345+
el.classList.remove(CLASS_NAMES.overflowHidden);
346+
};
347+
337348
/**
338349
* Verifies if an element has defined an iteration CSS property
339350
* @param {HTMLElement} element
@@ -385,7 +396,8 @@ const endVisibilityToggle = (element, opts) => {
385396
}
386397
if (opts.heightTransition || opts.widthTransition)
387398
endParentResize(element, opts);
388-
else if (opts.overflowHidden && element.parentElement)
399+
400+
if (opts.overflowHidden && element.parentElement)
389401
removeOverflowHidden(element.parentElement);
390402
};
391403

@@ -457,9 +469,10 @@ const animate = (element, action, id, opts = {}) => {
457469
action,
458470
widthTransition,
459471
heightTransition,
460-
overflowHidden,
461472
}));
462-
} else if (overflowHidden && element.parentElement)
473+
}
474+
475+
if (overflowHidden && element.parentElement)
463476
setOverflowHidden(element.parentElement);
464477
},
465478
motion: () => {

js-css-animations/resize-parent.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
* when child element is being animated
44
* @module resize-parent
55
*/
6-
import {
7-
CLASS_NAMES,
8-
CUSTOM_CSS_PROPERTIES,
9-
PROPERTY_NAMES,
10-
} from './globals.js';
6+
import { CUSTOM_CSS_PROPERTIES, PROPERTY_NAMES } from './globals.js';
117

128
import {
139
getParentMeasures,
@@ -66,30 +62,13 @@ const getDimension = (wTransit, hTransit) => {
6662
return dimension;
6763
};
6864

69-
/**
70-
* Adds a CSS class which will set the overflow property to 'clip' (or 'hidden')
71-
* @param {HTMLElement} el - The DOM element which will receive the CSS class
72-
*/
73-
const setOverflowHidden = el => {
74-
el.classList.add(CLASS_NAMES.overflowHidden);
75-
};
76-
77-
/**
78-
* Removes the CSS class which sets the overflow property to 'clip' (or 'hidden')
79-
* @param {HTMLElement} el - The DOM element with the CSS class to remove
80-
*/
81-
const removeOverflowHidden = el => {
82-
el.classList.remove(CLASS_NAMES.overflowHidden);
83-
};
84-
8565
/**
8666
* Handles parent element width/height transitions during child element's animation
8767
* @param {{
8868
* element: HTMLElement,
8969
* action: string,
9070
* widthTransition: boolean,
9171
* heightTransition: boolean,
92-
* overflowHidden: boolean
9372
* }} args - Containing all the information needed to initiate parent's dimensions transitions
9473
* @returns An object with the dimension(s) to transition and the parent element's measurements before and after the child element's animation is performed
9574
*/
@@ -101,7 +80,6 @@ const initParentResize = args => {
10180
const dimension = getDimension(widthTransition, heightTransition);
10281
setDimensionsTransitions(parentElement, widthTransition, heightTransition);
10382
setParentCssProperties(element);
104-
if (args.overflowHidden) setOverflowHidden(parentElement);
10583
setParentMaxMeasures({
10684
parentState: 'initial',
10785
element,
@@ -124,12 +102,6 @@ const endParentResize = (element, opts) => {
124102
removeDimensionMax(parentElement, 'width');
125103
removeCustomCssProperties(parentElement);
126104
removeDimensionsTransitions(parentElement, wTransit, hTransit);
127-
removeOverflowHidden(parentElement);
128105
};
129106

130-
export {
131-
initParentResize,
132-
endParentResize,
133-
setOverflowHidden,
134-
removeOverflowHidden,
135-
};
107+
export { initParentResize, endParentResize };

0 commit comments

Comments
 (0)