Skip to content

Commit

Permalink
Fixes #383 - adds support for disableActiveInteraction option
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranahmedse committed Aug 4, 2023
1 parent c2d9950 commit 4ccc492
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ <h2>Usage and Demo</h2>
description: "You can now have popovers without elements as well",
},
},
{
element: '.buttons',
popover: {
title: "Buttons",
description: "Here are some buttons",
},
},
{
element: "#scrollable-area",
popover: {
Expand Down Expand Up @@ -457,6 +464,7 @@ <h2>Usage and Demo</h2>
const driverObj = driver({
animate: true,
steps: basicTourSteps,
disableActiveInteraction: true,
showProgress: true,
progressText: "{{current}} of {{total}} done",
onPopoverRender: (popover) => {
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type Config = {
stagePadding?: number;
stageRadius?: number;

disableActiveInteraction?: boolean;

allowKeyboardControl?: boolean;

// Popover specific configuration
Expand Down Expand Up @@ -54,6 +56,7 @@ export function configure(config: Config = {}) {
allowClose: true,
overlayOpacity: 0.7,
smoothScroll: false,
disableActiveInteraction: false,
showProgress: false,
stagePadding: 10,
stageRadius: 5,
Expand Down
10 changes: 8 additions & 2 deletions src/driver.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
transition-duration: 200ms;
}

.driver-popover-close-btn:hover, .driver-popover-close-btn:focus {
.driver-popover-close-btn:hover,
.driver-popover-close-btn:focus {
color: #2d2d2d;
}

Expand Down Expand Up @@ -140,7 +141,12 @@
overflow: hidden !important;
}

.driver-popover-footer button:hover, .driver-popover-footer button:focus {
.driver-no-interaction, .driver-no-interaction * {
pointer-events: none !important;
}

.driver-popover-footer button:hover,
.driver-popover-footer button:focus {
background-color: #f7f7f7;
}

Expand Down
9 changes: 7 additions & 2 deletions src/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
renderPopover(toElement, toStep);
}

fromElement.classList.remove("driver-active-element");
fromElement.classList.remove("driver-active-element", "driver-no-interaction");
fromElement.removeAttribute("aria-haspopup");
fromElement.removeAttribute("aria-expanded");
fromElement.removeAttribute("aria-controls");

const disableActiveInteraction = getConfig("disableActiveInteraction");
if (disableActiveInteraction) {
toElement.classList.add("driver-no-interaction");
}

toElement.classList.add("driver-active-element");
toElement.setAttribute("aria-haspopup", "dialog");
toElement.setAttribute("aria-expanded", "true");
Expand All @@ -160,7 +165,7 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
export function destroyHighlight() {
document.getElementById("driver-dummy-element")?.remove();
document.querySelectorAll(".driver-active-element").forEach(element => {
element.classList.remove("driver-active-element");
element.classList.remove("driver-active-element", "driver-no-interaction");
element.removeAttribute("aria-haspopup");
element.removeAttribute("aria-expanded");
element.removeAttribute("aria-controls");
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export function getFocusableElements(parentEls: Element[] | HTMLElement[]) {

return [...(isParentFocusable ? [parentEl as HTMLElement] : []), ...focusableEls];
})
.filter(el => isElementVisible(el));
.filter(el => {
return getComputedStyle(el).pointerEvents !== "none" && isElementVisible(el);
});
}

export function bringInView(element: Element) {
Expand Down

0 comments on commit 4ccc492

Please sign in to comment.