Skip to content

Commit 6bf3ab4

Browse files
committed
Add aria attributes
1 parent 0f198fd commit 6bf3ab4

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/driver.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
.driver-popover-progress-text {
109109
font-size: 13px;
110110
font-weight: 400;
111-
color: #a2a2a2;
111+
color: #727272;
112112
zoom: 1;
113113
}
114114

src/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { refreshActiveHighlight } from "./highlight";
22
import { emit } from "./emitter";
33
import { getState, setState } from "./state";
44
import { getConfig } from "./config";
5-
import { getFocusableElements, isElementVisible } from "./utils";
5+
import { getFocusableElements } from "./utils";
66

77
export function requireRefresh() {
88
const resizeTimeout = getState("__resizeTimeout");

src/highlight.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,22 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
146146
}
147147

148148
fromElement.classList.remove("driver-active-element");
149+
fromElement.removeAttribute("aria-haspopup");
150+
fromElement.removeAttribute("aria-expanded");
151+
fromElement.removeAttribute("aria-controls");
152+
149153
toElement.classList.add("driver-active-element");
154+
toElement.setAttribute("aria-haspopup", "dialog");
155+
toElement.setAttribute("aria-expanded", "true");
156+
toElement.setAttribute("aria-controls", "driver-popover-content");
150157
}
151158

152159
export function destroyHighlight() {
153160
document.getElementById("driver-dummy-element")?.remove();
154161
document.querySelectorAll(".driver-active-element").forEach(element => {
155162
element.classList.remove("driver-active-element");
163+
element.removeAttribute("aria-haspopup");
164+
element.removeAttribute("aria-expanded");
165+
element.removeAttribute("aria-controls");
156166
});
157167
}

src/popover.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ export function renderPopover(element: Element, step: DriveStep) {
138138
popoverWrapper.style.bottom = "";
139139
popoverWrapper.style.right = "";
140140

141+
popoverWrapper.id = "driver-popover-content";
142+
popoverWrapper.setAttribute("role", "dialog");
143+
popoverWrapper.setAttribute("aria-labelledby", "driver-popover-title");
144+
popoverWrapper.setAttribute("aria-describedby", "driver-popover-description");
145+
141146
// Reset the classes responsible for the arrow position
142147
const popoverArrow = popover.arrow;
143148
popoverArrow.className = "driver-popover-arrow";
@@ -593,21 +598,25 @@ function createPopover(): PopoverDOM {
593598
const arrow = document.createElement("div");
594599
arrow.classList.add("driver-popover-arrow");
595600

596-
const title = document.createElement("div");
601+
const title = document.createElement("header");
602+
title.id = "driver-popover-title";
597603
title.classList.add("driver-popover-title");
598604
title.style.display = "none";
599605
title.innerText = "Popover Title";
600606

601607
const description = document.createElement("div");
608+
description.id = "driver-popover-description";
602609
description.classList.add("driver-popover-description");
603610
description.style.display = "none";
604611
description.innerText = "Popover description is here";
605612

606613
const closeButton = document.createElement("button");
614+
closeButton.type = "button";
607615
closeButton.classList.add("driver-popover-close-btn");
616+
closeButton.setAttribute("aria-label", "Close");
608617
closeButton.innerHTML = "×";
609618

610-
const footer = document.createElement("div");
619+
const footer = document.createElement("footer");
611620
footer.classList.add("driver-popover-footer");
612621

613622
const progress = document.createElement("span");
@@ -618,10 +627,12 @@ function createPopover(): PopoverDOM {
618627
footerButtons.classList.add("driver-popover-navigation-btns");
619628

620629
const previousButton = document.createElement("button");
630+
previousButton.type = "button";
621631
previousButton.classList.add("driver-popover-prev-btn");
622632
previousButton.innerHTML = "← Previous";
623633

624634
const nextButton = document.createElement("button");
635+
nextButton.type = "button";
625636
nextButton.classList.add("driver-popover-next-btn");
626637
nextButton.innerHTML = "Next →";
627638

0 commit comments

Comments
 (0)