Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
#626 fix animation being removed when the subtree of a flow changes d…
Browse files Browse the repository at this point in the history
…uring the animation (#632)
  • Loading branch information
driskull authored Dec 11, 2019
1 parent f9f6d1a commit 876b896
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/components/calcite-flow/calcite-flow.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ describe("calcite-flow", () => {
expect(frame).toHaveClass(CSS.frameAdvancing);
});

it("frame advancing should add animation class when subtree is modified", async () => {
const page = await newE2EPage();

await page.setContent("<calcite-flow><calcite-flow-item>flow1</calcite-flow-item></calcite-flow>");

const element = await page.find("calcite-flow");

element.innerHTML = `<calcite-flow-item>flow1</calcite-flow-item><calcite-flow-item id="flow2">flow2</calcite-flow-item>`;

await page.waitForChanges();

const item2 = await page.find(`calcite-flow-item[id=flow2]`);

item2.innerHTML = "new flow2 subtree content";

await page.waitForChanges();

const frame = await page.find(`calcite-flow >>> .${CSS.frame}`);

expect(frame).toHaveClass(CSS.frameAdvancing);
});

it("frame retreating should add animation class", async () => {
const page = await newE2EPage();

Expand Down
15 changes: 6 additions & 9 deletions src/components/calcite-flow/calcite-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ export class CalciteFlow {
// --------------------------------------------------------------------------

getFlowDirection = (oldFlowCount: number, newFlowCount: number): FlowDirection | null => {
const flowCountChanged = oldFlowCount !== newFlowCount;

if (!flowCountChanged) {
return null;
}

const allowRetreatingDirection = oldFlowCount > 1;
const allowAdvancingDirection = oldFlowCount && newFlowCount > 1;

Expand All @@ -102,7 +96,6 @@ export class CalciteFlow {
const oldFlowCount = flows.length;
const newFlowCount = newFlows.length;

const flowDirection = this.getFlowDirection(oldFlowCount, newFlowCount);
const activeFlow = newFlows[newFlowCount - 1];
const previousFlow = newFlows[newFlowCount - 2];

Expand All @@ -118,8 +111,12 @@ export class CalciteFlow {
}

this.flows = newFlows;
this.flowCount = newFlowCount;
this.flowDirection = flowDirection;

if (oldFlowCount !== newFlowCount) {
const flowDirection = this.getFlowDirection(oldFlowCount, newFlowCount);
this.flowCount = newFlowCount;
this.flowDirection = flowDirection;
}
};

flowItemObserver = new MutationObserver(this.updateFlowProps);
Expand Down

0 comments on commit 876b896

Please sign in to comment.