Skip to content

Commit 939db17

Browse files
authored
fix(perf): pause loading icon animation on initial load (#1325)
* fix(perf): pause loading icon animation on initial load * call pauseAnimations conditionally
1 parent b880f1d commit 939db17

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/autocomplete-js/src/elements/LoadingIcon.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,19 @@ export const LoadingIcon: AutocompleteElement<
3434
/>
3535
</circle>`;
3636

37+
const pauseAnimations = () => {
38+
// Wait until the element is in the DOM.
39+
if (!element.parentElement) {
40+
setTimeout(pauseAnimations, 0);
41+
return;
42+
}
43+
44+
element.pauseAnimations();
45+
};
46+
47+
if ('pauseAnimations' in element) {
48+
pauseAnimations();
49+
}
50+
3751
return element;
3852
};

0 commit comments

Comments
 (0)