Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export type Config = {
prevBtnText?: string;
doneBtnText?: string;

// Attach the popover and overlay to a specific element, defaults to document.body
// but the position is still calculated based on window
attach?: string;

// Called after the popover is rendered
onPopoverRender?: (popover: PopoverDOM, opts: { config: Config; state: State, driver: Driver }) => void;

Expand Down Expand Up @@ -88,3 +92,7 @@ export function setCurrentDriver(driver: Driver) {
export function getCurrentDriver() {
return currentDriver;
}

export function getAttachElement() {
return currentConfig.attach && document.querySelector(currentConfig.attach) || document.body;
}
4 changes: 2 additions & 2 deletions src/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DriveStep } from "./driver";
import { refreshOverlay, trackActiveElement, transitionStage } from "./overlay";
import { getConfig, getCurrentDriver } from "./config";
import { getAttachElement, getConfig, getCurrentDriver } from "./config";
import { hidePopover, renderPopover, repositionPopover } from "./popover";
import { bringInView } from "./utils";
import { getState, setState } from "./state";
Expand All @@ -22,7 +22,7 @@ function mountDummyElement(): Element {
element.style.top = "50%";
element.style.left = "50%";

document.body.appendChild(element);
getAttachElement().appendChild(element);

return element;
}
Expand Down
4 changes: 2 additions & 2 deletions src/overlay.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { easeInOutQuad } from "./utils";
import { onDriverClick } from "./events";
import { emit } from "./emitter";
import { getConfig } from "./config";
import { getAttachElement, getConfig } from "./config";
import { getState, setState } from "./state";

export type StageDefinition = {
Expand Down Expand Up @@ -75,7 +75,7 @@ export function refreshOverlay() {

function mountOverlay(stagePosition: StageDefinition) {
const overlaySvg = createOverlaySvg(stagePosition);
document.body.appendChild(overlaySvg);
getAttachElement().appendChild(overlaySvg);

onDriverClick(overlaySvg, e => {
const target = e.target as SVGElement;
Expand Down
6 changes: 3 additions & 3 deletions src/popover.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, DriverHook, getConfig, getCurrentDriver } from "./config";
import { Config, DriverHook, getAttachElement, getConfig, getCurrentDriver } from "./config";
import { Driver, DriveStep } from "./driver";
import { emit } from "./emitter";
import { onDriverClick } from "./events";
Expand Down Expand Up @@ -61,11 +61,11 @@ export function hidePopover() {
export function renderPopover(element: Element, step: DriveStep) {
let popover = getState("popover");
if (popover) {
document.body.removeChild(popover.wrapper);
getAttachElement().removeChild(popover.wrapper);
}

popover = createPopover();
document.body.appendChild(popover.wrapper);
getAttachElement().appendChild(popover.wrapper);

const {
title,
Expand Down