richie-south commited on
Commit
c9713c7
·
unverified ·
1 Parent(s): fa7aa82

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

Browse files
Files changed (2) hide show
  1. src/driver.ts +1 -1
  2. src/highlight.ts +2 -1
src/driver.ts CHANGED
@@ -8,7 +8,7 @@ import { getState, resetState, setState } from "./state";
8
  import "./driver.css";
9
 
10
  export type DriveStep = {
11
- element?: string | Element;
12
  onHighlightStarted?: DriverHook;
13
  onHighlighted?: DriverHook;
14
  onDeselected?: DriverHook;
 
8
  import "./driver.css";
9
 
10
  export type DriveStep = {
11
+ element?: string | Element | (() => Element);
12
  onHighlightStarted?: DriverHook;
13
  onHighlighted?: DriverHook;
14
  onDeselected?: DriverHook;
src/highlight.ts CHANGED
@@ -29,7 +29,8 @@ function mountDummyElement(): Element {
29
 
30
  export function highlight(step: DriveStep) {
31
  const { element } = step;
32
- let elemObj = typeof element === "string" ? document.querySelector(element) : element;
 
33
 
34
  // If the element is not found, we mount a 1px div
35
  // at the center of the screen to highlight and show
 
29
 
30
  export function highlight(step: DriveStep) {
31
  const { element } = step;
32
+ let elemObj =
33
+ typeof element === "function" ? element() : typeof element === "string" ? document.querySelector(element) : element;
34
 
35
  // If the element is not found, we mount a 1px div
36
  // at the center of the screen to highlight and show