Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition in drawer animations #1958

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix race condition when closing the drawer immediately after it finishes opening",
"packageName": "@ni/nimble-components",
"email": "20542556+mollykreis@users.noreply.github.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions packages/nimble-components/src/drawer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ export class Drawer<CloseReason = void> extends FoundationElement {
}

private triggerAnimation(): void {
// Read the offsetHeight of the dialog to trigger a reflow. This guarantees that the browser
// has processed the 'animating' class being removed before trying to readd it, even if the previous
// animation has just finished. Otherwise, problems can occur. For example, trying to close the
// drawer immediately after the opening animation ends does not actually close the drawer.
// https://github.com/ni/nimble/issues/1994
void this.dialog.offsetHeight;
mollykreis marked this conversation as resolved.
Show resolved Hide resolved

this.dialog.classList.add('animating');
if (this.closing) {
this.dialog.classList.add('closing');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ describe('Drawer', () => {
await expectAsync(promise).toBePending();
});

// Firefox skipped, see: https://github.com/ni/nimble/issues/1937
it('should resolve promise if drawer completely opens before being closed #SkipFirefox', async () => {
it('should resolve promise if drawer completely opens before being closed', async () => {
const promise = element.show();
await completeAnimationAsync(element);
element.close();
Expand Down
Loading