mirror of
https://github.com/kamranahmedse/driver.js.git
synced 2026-10-31 03:52:13 +08:00
feat: allow element to be type function that returns an element (#463)
This commit is contained in:
+1
-1
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user