Skip to content

Apply driver button style through CSS class #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions docs/src/content/guides/buttons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ You can add custom buttons using `onPopoverRender` callback. This callback is ca
onPopoverRender: (popover, { config, state }) => {
const firstButton = document.createElement("button");
firstButton.innerText = "Go to First";
// This class adds the default button styling. It can be left out if you want your own styles to apply
firstButton.classList.add("driver-popover-footer-btn");
popover.footerButtons.appendChild(firstButton);

firstButton.addEventListener("click", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/driver.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
zoom: 1;
}

.driver-popover-footer button {
.driver-popover-footer-btn {
all: unset;
display: inline-block;
box-sizing: border-box;
Expand Down
11 changes: 7 additions & 4 deletions src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,11 @@ export function renderPopover(element: Element, step: DriveStep) {
return (
!popover?.description.contains(target) &&
!popover?.title.contains(target) &&
typeof target.className === "string" &&
target.className.includes("driver-popover")
typeof target.className === "string" && (
target.classList.contains("driver-popover-prev-btn") ||
target.classList.contains("driver-popover-next-btn") ||
target.classList.contains("driver-popover-close-btn")
)
);
Comment on lines 207 to 215
Copy link
Contributor Author

@jarikmarwede jarikmarwede Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this code makes the most sense now. Maybe it can be simplified, but I haven't fully understood what it is supposed to do in the first place.
The reason I had to change it is that the previous check wasn't specific enough and would capture click events of every button with the new driver-popover-footer-btn class, including the ones added by users that wanted to add a custom button but still keep the default button style.

}
);
Expand Down Expand Up @@ -660,12 +663,12 @@ function createPopover(): PopoverDOM {

const previousButton = document.createElement("button");
previousButton.type = "button";
previousButton.classList.add("driver-popover-prev-btn");
previousButton.classList.add("driver-popover-prev-btn", "driver-popover-footer-btn");
previousButton.innerHTML = "← Previous";

const nextButton = document.createElement("button");
nextButton.type = "button";
nextButton.classList.add("driver-popover-next-btn");
nextButton.classList.add("driver-popover-next-btn", "driver-popover-footer-btn");
nextButton.innerHTML = "Next →";

footerButtons.appendChild(previousButton);
Expand Down