Skip to content

Commit 85e75bd

Browse files
authored
feat(morph): add abort parameter to cancel function (quasarframework#7538)
1 parent 5a1e4d6 commit 85e75bd

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

ui/src/utils/morph.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,18 @@ export default function morph (_options) {
660660
animationTo.addEventListener('finish', cleanup)
661661
animationTo.addEventListener('cancel', cleanup)
662662

663-
cancel = () => {
663+
cancel = abort => {
664664
// we are not in a morph that we can cancel
665665
if (cancelStatus === true || animationTo === void 0) {
666666
return false
667667
}
668668

669+
if (abort === true) {
670+
cleanup()
671+
672+
return true
673+
}
674+
669675
endElementTo = endElementTo !== true
670676

671677
animationFromClone !== void 0 && animationFromClone.reverse()
@@ -855,12 +861,18 @@ export default function morph (_options) {
855861
elTo.addEventListener('animationend', cleanup)
856862
elTo.addEventListener('animationcancel', cleanup)
857863

858-
cancel = () => {
864+
cancel = abort => {
859865
// we are not in a morph that we can cancel
860866
if (cancelStatus === true || !elTo || !elFromClone || !elToClone) {
861867
return false
862868
}
863869

870+
if (abort === true) {
871+
cleanup()
872+
873+
return true
874+
}
875+
864876
endElementTo = endElementTo !== true
865877

866878
animationDirection = animationDirection === 'normal' ? 'reverse' : 'normal'
@@ -924,5 +936,5 @@ export default function morph (_options) {
924936
// returns:
925937
// false if the cancel cannot be performed (the morph ended already or has not started)
926938
// true else
927-
return () => cancel()
939+
return abort => cancel(abort)
928940
}

ui/types/utils.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function throttle<F extends (...args: any[]) => any>(
2727
export function uid(): string;
2828

2929
interface MorphOptions {
30-
from: Element | string | (() => Element | undefined);
31-
to?: Element | string | (() => Element | undefined);
30+
from: Element | string | (() => Element | null | undefined);
31+
to?: Element | string | (() => Element | null | undefined);
3232
onToggle?: () => void;
3333
waitFor?: number | 'transitionend' | Promise<any>;
3434

@@ -52,4 +52,4 @@ interface MorphOptions {
5252
onReady?: (end: 'to' | 'from') => void;
5353
}
5454

55-
export function morph(options: MorphOptions): () => boolean;
55+
export function morph(options: MorphOptions): (abort?: boolean) => boolean;

0 commit comments

Comments
 (0)