-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix regression causing open/close events from emitting in proper…
… order (#9560) **Related Issue:** #9559 ## Summary This fixes `openCloseComponent.onToggleOpenCloseComponent` to emit beforeOpen/Close events when the associated transition starts and emits open/close when the transition ends. This regression was introduced by #9341 and would cause `beforeOpen`/`open` or `beforeClose`/`close` to emit immediately after another after the transition was done. ### Notable changes * adds spec test to add coverage for `onToggleOpenCloseComponent` * enhances `whenAnimationDone`/`whenTransitionDone` to accept callbacks for both start and end phases * exposes `readTask` from `openCloseComponent` to allow for stubbing (stubbing Stencil's utility is not possible because the core module getters are non-configurable) * extracts animation/transition helpers for spec tests to individual modules
- Loading branch information
Showing
7 changed files
with
345 additions
and
103 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/calcite-components/src/tests/spec-helpers/animationEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export interface AnimationEventDispatcher { | ||
(element: HTMLElement, type: "animationstart" | "animationend", animationName: string): void; | ||
} | ||
|
||
/** | ||
* Must be called in a `beforeEach` block to create a animation event dispatcher. | ||
*/ | ||
export function createAnimationEventDispatcher(): AnimationEventDispatcher { | ||
// we define AnimationEvent since JSDOM doesn't support it yet - | ||
class AnimationEvent extends window.Event { | ||
elapsedTime: number; | ||
|
||
animationName: string; | ||
|
||
constructor(type: string, eventInitDict: EventInit & Partial<{ elapsedTime: number; animationName: string }>) { | ||
super(type, eventInitDict); | ||
this.elapsedTime = eventInitDict.elapsedTime; | ||
this.animationName = eventInitDict.animationName; | ||
} | ||
} | ||
|
||
return (element: HTMLElement, type: "animationstart" | "animationend", animationName: string): void => { | ||
element.dispatchEvent(new AnimationEvent(type, { animationName })); | ||
}; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/calcite-components/src/tests/spec-helpers/computedStyle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Mocks `getComputedStyle` to return the provided values for the provided element. | ||
* This is needed due to JSDOM issue with getComputedStyle - https://github.com/jsdom/jsdom/issues/3090 | ||
* | ||
* @param element | ||
* @param fakeComputedStyle | ||
*/ | ||
export function mockGetComputedStyleFor(element: Element, fakeComputedStyle: Partial<CSSStyleDeclaration>): void { | ||
jest.spyOn(window, "getComputedStyle").mockImplementation((el: Element): CSSStyleDeclaration => { | ||
if (el === element) { | ||
return fakeComputedStyle as CSSStyleDeclaration; | ||
} | ||
}); | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/calcite-components/src/tests/spec-helpers/transitionEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export interface TransitionEventDispatcher { | ||
(element: HTMLElement, type: "transitionstart" | "transitionend", propertyName: string): void; | ||
} | ||
|
||
/** | ||
* Must be called in a `beforeEach` block to create a transition event dispatcher. | ||
*/ | ||
export function createTransitionEventDispatcher(): TransitionEventDispatcher { | ||
// we define TransitionEvent since JSDOM doesn't support it yet - https://github.com/jsdom/jsdom/issues/1781 | ||
class TransitionEvent extends window.Event { | ||
elapsedTime: number; | ||
|
||
propertyName: string; | ||
|
||
constructor(type: string, eventInitDict: EventInit & Partial<{ elapsedTime: number; propertyName: string }>) { | ||
super(type, eventInitDict); | ||
this.elapsedTime = eventInitDict.elapsedTime; | ||
this.propertyName = eventInitDict.propertyName; | ||
} | ||
} | ||
|
||
return (element: HTMLElement, type: "transitionstart" | "transitionend", propertyName: string): void => { | ||
element.dispatchEvent(new TransitionEvent(type, { propertyName })); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.