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 opening animation when closing card #1990

Merged
merged 2 commits into from
Dec 30, 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
25 changes: 19 additions & 6 deletions packages/host/app/components/operator-mode/stack-item.gts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ export default class OperatorModeStackItem extends Component<Signature> {
}

private closeItem = dropTask(async () => {
await this.startAnimation.perform('closing');
this.args.close(this.args.item);
await this.args.dismissStackedCardsAbove(this.args.index - 1);
});

@action private toggleSelect(cardDefOrId: CardDefOrId) {
Expand Down Expand Up @@ -523,10 +522,24 @@ export default class OperatorModeStackItem extends Component<Signature> {
return;
}
const animations = this.itemEl.getAnimations() || [];
Promise.all(animations.map((animation) => animation.finished)).then(() => {
this.animationType = undefined;
resolve();
});
Promise.all(animations.map((animation) => animation.finished))
.then(() => {
this.animationType = undefined;
resolve();
})
.catch((e) => {
// AbortError is expected in two scenarios:
// 1. Multiple stack items are animating in parallel (eg. closing and moving forward)
// and some elements get removed before their animations complete
// 2. Tests running with animation-duration: 0s can cause
// animations to abort before they're properly tracked
if (e.name === 'AbortError') {
this.animationType = undefined;
resolve();
} else {
console.error(e);
}
});
}

private setupContentEl = (el: HTMLElement) => {
Expand Down
28 changes: 28 additions & 0 deletions packages/host/tests/integration/components/operator-mode-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ module('Integration | operator-mode', function (hooks) {
.includesText('Person');

await click('[data-test-stack-card-index="1"] [data-test-close-button]');
await waitFor('[data-test-stack-card-index="1"]', { count: 0 });
assert.dom(`[data-test-stack-card-index="1"]`).doesNotExist();
});

Expand Down Expand Up @@ -1587,6 +1588,10 @@ module('Integration | operator-mode', function (hooks) {
await click(`[data-test-search-sheet-cancel-button]`);
await click(`[data-test-stack-card-index="1"] [data-test-close-button]`);

await waitUntil(
() => !document.querySelector('[data-test-stack-card-index="1"]'),
);

await waitFor(`[data-test-cards-grid-item]`);
await click(`[data-test-cards-grid-item="${testRealmURL}Person/burcu"]`);
await waitFor(`[data-test-stack-card-index="1"]`);
Expand Down Expand Up @@ -3038,4 +3043,27 @@ module('Integration | operator-mode', function (hooks) {
.dom(`[data-test-stack-card="${testRealmURL}Person/fadhlan"]`)
.doesNotHaveClass('opening-animation');
});

test('close card should not trigger opening animation again', async function (assert) {
await setCardInOperatorModeState(`${testRealmURL}grid`);
await renderComponent(
class TestDriver extends GlimmerComponent {
<template>
<OperatorMode @onClose={{noop}} />
<CardPrerender />
</template>
},
);
await waitFor(`[data-test-stack-card="${testRealmURL}grid"]`);

await click(`[data-test-boxel-filter-list-button="All Cards"]`);
await waitFor(`[data-test-cards-grid-item]`);
await click(`[data-test-cards-grid-item="${testRealmURL}Person/fadhlan"]`);
await click(`[data-test-stack-card-index="1"] [data-test-close-button]`);

await waitFor(`[data-test-stack-card-index="0"]`);
assert
.dom(`[data-test-stack-card-index="0"]`)
.doesNotHaveClass('opening-animation');
});
});
Loading