Skip to content

Commit 546b381

Browse files
authored
Merge pull request #295 from pathsim/fix/tour-next-button
fix: restore tour Next button (#294)
2 parents b11c1be + d44da90 commit 546b381

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/lib/tours/builder.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ function openOnNext(opener: () => Promise<void>): DriverHook {
3737
};
3838
}
3939

40+
type PopoverSpec = NonNullable<DriveStep['popover']>;
41+
42+
/** Drop keys whose value is `undefined` from a popover spec.
43+
*
44+
* driver.js merges a step's `popover` *over* its own defaults — the step
45+
* spread comes last. An explicit `onNextClick: undefined` therefore clobbers
46+
* driver.js's built-in Next handler, leaving the button rendered but inert.
47+
* Builders that forward optional hooks (`rawStep`, `blockStep`, `actionStep`)
48+
* must prune undefined keys before handing the popover to driver.js. */
49+
function prunePopover(popover: PopoverSpec): PopoverSpec {
50+
for (const key of Object.keys(popover) as (keyof PopoverSpec)[]) {
51+
if (popover[key] === undefined) delete popover[key];
52+
}
53+
return popover;
54+
}
55+
4056
const FLOATING_POPOVER = { popoverClass: 'tour-floating' } as const;
4157
const FLOATING_BR = {
4258
side: 'top' as Side,
@@ -296,13 +312,13 @@ export function actionStep(opts: ActionStep): DriveStep[] {
296312
{
297313
element: opts.result,
298314
onHighlightStarted: opts.beforeResult,
299-
popover: {
315+
popover: prunePopover({
300316
title: opts.resultTitle,
301317
description: opts.resultBody,
302318
side: opts.resultPosition?.side ?? 'right',
303319
align: opts.resultPosition?.align ?? 'center',
304320
onNextClick: opts.onResultNext
305-
}
321+
})
306322
}
307323
];
308324
}
@@ -328,13 +344,13 @@ export function blockStep(opts: BlockStep): DriveStep {
328344
onHighlightStarted: opts.onHighlightStarted,
329345
onHighlighted: opts.onHighlighted,
330346
onDeselected: opts.onDeselected,
331-
popover: {
347+
popover: prunePopover({
332348
title: opts.title,
333349
description: opts.body,
334350
side: opts.side ?? 'right',
335351
align: opts.align ?? 'center',
336352
onNextClick: opts.onNextClick
337-
}
353+
})
338354
};
339355
}
340356

@@ -364,14 +380,14 @@ export function rawStep(opts: RawStep): DriveStep {
364380
element: opts.element,
365381
onHighlightStarted: opts.onHighlightStarted,
366382
onDeselected: opts.onDeselected,
367-
popover: {
383+
popover: prunePopover({
368384
title: opts.title,
369385
description: opts.body,
370386
side: opts.side ?? 'right',
371387
align: opts.align ?? 'center',
372388
popoverClass: opts.popoverClass,
373389
onNextClick: opts.onNextClick,
374390
onPopoverRender: opts.onPopoverRender
375-
}
391+
})
376392
};
377393
}

0 commit comments

Comments
 (0)