Fixing animation bugs

This commit is contained in:
Jake Archibald
2018-10-27 14:40:52 +01:00
parent ac4f845d8e
commit c8e0c56687
2 changed files with 11 additions and 3 deletions

View File

@@ -22,6 +22,9 @@ async function close(content: HTMLElement) {
content.removeAttribute('expanded'); content.removeAttribute('expanded');
content.setAttribute('aria-expanded', 'false'); content.setAttribute('aria-expanded', 'false');
// Wait a microtask so other calls to open/close can get the final sizes.
await null;
await transitionHeight(content, { await transitionHeight(content, {
from, from,
to: 0, to: 0,
@@ -37,8 +40,13 @@ async function open(content: HTMLElement) {
content.setAttribute('expanded', ''); content.setAttribute('expanded', '');
content.setAttribute('aria-expanded', 'true'); content.setAttribute('aria-expanded', 'true');
const to = content.getBoundingClientRect().height;
// Wait a microtask so other calls to open/close can get the final sizes.
await null;
await transitionHeight(content, { await transitionHeight(content, {
from, from, to,
duration: 300, duration: 300,
}); });

View File

@@ -280,9 +280,9 @@ export async function transitionHeight(el: HTMLElement, opts: TransitionOptions)
} }
el.style.height = from + 'px'; el.style.height = from + 'px';
el.style.transition = `height ${duration}ms ${easing}`;
// Force a style calc so the browser picks up the start value. // Force a style calc so the browser picks up the start value.
getComputedStyle(el).height; getComputedStyle(el).transform;
el.style.transition = `height ${duration}ms ${easing}`;
el.style.height = to + 'px'; el.style.height = to + 'px';
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {