feat: allow element to be type function that returns an element (#463)

This commit is contained in:
Richard
2025-01-22 17:19:16 +00:00
committed by GitHub
parent fa7aa82a04
commit c9713c715d
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ import { getState, resetState, setState } from "./state";
import "./driver.css";
export type DriveStep = {
element?: string | Element;
element?: string | Element | (() => Element);
onHighlightStarted?: DriverHook;
onHighlighted?: DriverHook;
onDeselected?: DriverHook;
+2 -1
View File
@@ -29,7 +29,8 @@ function mountDummyElement(): Element {
export function highlight(step: DriveStep) {
const { element } = step;
let elemObj = typeof element === "string" ? document.querySelector(element) : element;
let elemObj =
typeof element === "function" ? element() : typeof element === "string" ? document.querySelector(element) : element;
// If the element is not found, we mount a 1px div
// at the center of the screen to highlight and show