From 0928c8579807b8ea0032eb957f80a6b1a0299f8d Mon Sep 17 00:00:00 2001 From: Piyush Singh Date: Mon, 28 Sep 2026 15:02:58 +0530 Subject: [PATCH] fix(user-onboarding): restore tour button actions - shepherd.js expects a button's `action` to be the click handler itself, but `TourButton.action` was typed as a function that returns a handler - under the stricter TypeScript 6 checks that came with the Angular 22 upgrade, the handlers in `actionAssignment` were wrapped to match that type, so clicking Next, Previous or a custom button returned the handler instead of running it - type `TourButton.action` as `Step.StepOptionsButton['action']` and assign the handlers directly again, matching the behaviour from before the upgrade - no regression expected: `actionAssignment` is the only place that sets `action`, apps that pass handlers still type-check, and the library builds on Angular 22 / TypeScript 6 GH-87 --- .../user-onboarding-element/package.json | 2 +- .../src/lib/tour-service.service.ts | 17 +++++++++-------- .../src/models/tour-button.ts | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/user-onboarding/projects/user-onboarding-element/package.json b/packages/user-onboarding/projects/user-onboarding-element/package.json index d8c1ce7..405fe5a 100644 --- a/packages/user-onboarding/projects/user-onboarding-element/package.json +++ b/packages/user-onboarding/projects/user-onboarding-element/package.json @@ -22,5 +22,5 @@ "access": "public", "directory": "dist" }, - "hash": "e65f7bb96c4788dba8137df5a821e2eb2d2246b7162bcef11c4e792ad3466ab2" + "hash": "03edeb8282be21019cd2abf2f0247a97fa7192cfe82ffd5228091594eb52a385" } \ No newline at end of file diff --git a/packages/user-onboarding/projects/user-onboarding-lib/src/lib/tour-service.service.ts b/packages/user-onboarding/projects/user-onboarding-lib/src/lib/tour-service.service.ts index 458d210..1d142f0 100644 --- a/packages/user-onboarding/projects/user-onboarding-lib/src/lib/tour-service.service.ts +++ b/packages/user-onboarding/projects/user-onboarding-lib/src/lib/tour-service.service.ts @@ -103,16 +103,13 @@ export class TourServiceService { props: Props, ): void { if (b.key === 'prevAction') { - // Fixed: Wrapped functions to return the action as expected by shepherd.js type definition - b.action = () => + b.action = e.prevRoute === e.currentRoute ? wrapperNormalPrev : wrapperPrev; } else if (b.key === 'nextAction') { - // Fixed: Wrapped functions to return the action as expected by shepherd.js type definition - b.action = () => + b.action = e.nextRoute === e.currentRoute ? wrapperNormalNext : wrapperNext; } else { - // Fixed: Wrapped bind result to return the action as expected by shepherd.js type definition - b.action = () => func.bind({tour: this.tour, tourId, props}); + b.action = func.bind({tour: this.tour, tourId, props}); } } @@ -182,7 +179,9 @@ export class TourServiceService { e.buttons?.forEach(b => { const key = b.key; // Fixed: Added type assertion for key and func since getFnByKey returns Function but we need () => void - const func = this.tourStoreService.getFnByKey(key as string) as () => void; + const func = this.tourStoreService.getFnByKey( + key as string, + ) as () => void; const wrapperNext = () => { this.navigateAndMoveToNextStep(e, tourInstance, tourState, index); }; @@ -237,7 +236,9 @@ export class TourServiceService { er.buttons?.forEach(br => { const k = br.key; // Fixed: Added type assertion for key and func since getFnByKey returns Function but we need () => void - const funcRemoved = this.tourStoreService.getFnByKey(k as string) as () => void; + const funcRemoved = this.tourStoreService.getFnByKey( + k as string, + ) as () => void; const wrapperNextRemoved = () => { this.navigateAndMoveToNextStepRemoved( er, diff --git a/packages/user-onboarding/projects/user-onboarding-lib/src/models/tour-button.ts b/packages/user-onboarding/projects/user-onboarding-lib/src/models/tour-button.ts index a94c809..dd879ef 100644 --- a/packages/user-onboarding/projects/user-onboarding-lib/src/models/tour-button.ts +++ b/packages/user-onboarding/projects/user-onboarding-lib/src/models/tour-button.ts @@ -5,7 +5,7 @@ import Step from 'shepherd.js/src/types/step'; export interface TourButton { - action?: () => Step.StepOptionsButton['action']; + action?: Step.StepOptionsButton['action']; classes?: string; text: string; key?: string;