Skip to content

Commit 29ad5a2

Browse files
committed
feat(): highlight active button in interactive demo
1 parent f35be07 commit 29ad5a2

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

template/components/InteractiveDemo/interactiveDemo.client.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
(n) => n instanceof HTMLElement
2323
);
2424

25+
optionButtons.forEach((btn) => {
26+
if (!btn.hasAttribute("data-default-variant")) {
27+
btn.setAttribute("data-default-variant", btn.getAttribute("data-variant") || "filled");
28+
}
29+
});
30+
2531
const getMode = () => root.getAttribute("data-mode") === "dark" ? "dark" : "light";
2632
const setMode = (mode) => root.setAttribute("data-mode", mode);
2733

@@ -56,8 +62,18 @@
5662

5763
optionButtons.forEach((btn) => {
5864
const id = btn.getAttribute("data-image-id");
59-
if (id === activeId) btn.setAttribute("data-active", "true");
60-
else btn.removeAttribute("data-active");
65+
const isActive = id === activeId;
66+
67+
if (isActive) {
68+
btn.setAttribute("data-active", "true");
69+
btn.setAttribute("aria-pressed", "true");
70+
const defaultVariant = btn.getAttribute("data-default-variant") || "filled";
71+
btn.setAttribute("data-variant", defaultVariant);
72+
} else {
73+
btn.removeAttribute("data-active");
74+
btn.setAttribute("aria-pressed", "false");
75+
btn.setAttribute("data-variant", "ghost");
76+
}
6177
});
6278

6379
cards.forEach((card) => {
@@ -96,7 +112,6 @@
96112
e.stopPropagation();
97113

98114
const to = btn.getAttribute("data-image-toggle-to");
99-
100115
if (isMode(to)) {
101116
setMode(to);
102117
update();

0 commit comments

Comments
 (0)