Skip to content

Commit df376f5

Browse files
Adds support for overlayClickBehavior (#600)
* Add overlay click behavior * Add overlay click behavior
1 parent e5baef1 commit df376f5

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

docs/src/content/guides/configuration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type Config = {
3434
// Opacity of the backdrop. (default: 0.5)
3535
overlayOpacity?: number;
3636
// What to do when the overlay backdrop is clicked.
37-
// Possible options are 'close' and 'nextStep'. (default: 'close')
38-
overlayClickBehavior?: string,
37+
// Possible options are 'close', 'nextStep', or a custom function. (default: 'close')
38+
overlayClickBehavior?: "close" | "nextStep" | ((element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void),
3939
// Distance between the highlighted element and the cutout. (default: 10)
4040
stagePadding?: number;
4141
// Radius of the cutout around the highlighted element. (default: 5)

index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ <h2>Highlight Feature</h2>
172172
<button id="transition-highlight-btn">Transition Highlight</button>
173173
<button id="disallow-close">Disallow Close</button>
174174
<button id="click-overlay-to-next">Click Overlay to Next</button>
175+
<button id="click-overlay-to-handle">Custom Overlay Click Handler</button>
175176
<button id="dark-highlight-btn">Super Dark Highlight</button>
176177
<button id="dim-highlight-btn">Super Dim Highlight</button>
177178
<button id="scrollable-area-btn">Scrollable Area</button>
@@ -1144,6 +1145,18 @@ <h2>Usage and Demo</h2>
11441145
driverObj.drive();
11451146
});
11461147

1148+
document.getElementById("click-overlay-to-handle").addEventListener("click", () => {
1149+
const driverObj = driver({
1150+
animate: true,
1151+
overlayClickBehavior: (element, step) => {
1152+
alert("Clicking me");
1153+
},
1154+
steps: basicTourSteps,
1155+
});
1156+
1157+
driverObj.drive();
1158+
});
1159+
11471160
document.getElementById("destroy-btn").addEventListener("click", () => {
11481161
driver().destroy();
11491162
});

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type Config = {
1616
overlayOpacity?: number;
1717
smoothScroll?: boolean;
1818
allowClose?: boolean;
19-
overlayClickBehavior?: "close" | "nextStep";
19+
overlayClickBehavior?: "close" | "nextStep" | DriverHook;
2020
stagePadding?: number;
2121
stageRadius?: number;
2222

src/driver.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ export function driver(options: Config = {}): Driver {
5959
return;
6060
}
6161

62+
if (typeof overlayClickBehavior === "function") {
63+
const activeStep = getState("__activeStep");
64+
const activeElement = getState("__activeElement");
65+
66+
overlayClickBehavior(activeElement, activeStep!, {
67+
config: getConfig(),
68+
state: getState(),
69+
driver: getCurrentDriver(),
70+
});
71+
72+
return;
73+
}
74+
6275
if (overlayClickBehavior === "nextStep") {
6376
moveNext();
6477
}

0 commit comments

Comments
 (0)