From 5541179b387ed8a1b5e457aeb47a35e6e7c62d4a Mon Sep 17 00:00:00 2001 From: GeoSot Date: Tue, 20 Jul 2021 17:20:43 +0300 Subject: [PATCH] Fix `Util.reflow` function and add documentation (#34543) * add documentation to reflow function * refactor to void as it should be Co-authored-by: XhmikosR --- js/src/util/index.js | 13 ++++++++++++- js/tests/unit/util/index.spec.js | 5 +++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/js/src/util/index.js b/js/src/util/index.js index a1af87aa47..f81d64837e 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -188,7 +188,18 @@ const findShadowRoot = element => { const noop = () => {} -const reflow = element => element.offsetHeight +/** + * Trick to restart an element's animation + * + * @param {HTMLElement} element + * @return void + * + * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation + */ +const reflow = element => { + // eslint-disable-next-line no-unused-expressions + element.offsetHeight +} const getjQuery = () => { const { jQuery } = window diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js index 9b5d7b70e2..38e94dc6bb 100644 --- a/js/tests/unit/util/index.spec.js +++ b/js/tests/unit/util/index.spec.js @@ -543,8 +543,9 @@ describe('Util', () => { fixtureEl.innerHTML = '
' const div = fixtureEl.querySelector('div') - - expect(Util.reflow(div)).toEqual(0) + const spy = spyOnProperty(div, 'offsetHeight') + Util.reflow(div) + expect(spy).toHaveBeenCalled() }) })