Skip to content

Commit ad632b6

Browse files
Replace SVG chevron in collapsibles button with CSS shape
Maintains visual consistency
1 parent 2e945e0 commit ad632b6

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

assets-src/js/main/collapsibles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let collapsibles = function () {
2020
headingsArray.forEach(function (heading, index) {
2121

2222
// Insert a button for opening/closing the collapsible section
23-
heading.innerHTML = '<button type="button" class="button--ghost" aria-expanded="false">' + heading.innerHTML + '<svg xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 320 512" class="icon icon--larger" focusable="false" aria-hidden="true" width="30px" height="30px"><path class="angle-down" d="M143 352.3L7 216.3c-9.4-9.4-9.4-24.6 0-33.9l22.6-22.6c9.4-9.4 24.6-9.4 33.9 0l96.4 96.4 96.4-96.4c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9l-136 136c-9.2 9.4-24.4 9.4-33.8 0z"/><path class="angle-up" d="M177 159.7l136 136c9.4 9.4 9.4 24.6 0 33.9l-22.6 22.6c-9.4 9.4-24.6 9.4-33.9 0L160 255.9l-96.4 96.4c-9.4 9.4-24.6 9.4-33.9 0L7 329.7c-9.4-9.4-9.4-24.6 0-33.9l136-136c9.4-9.5 24.6-9.5 34-.1z"/></svg></button>';
23+
heading.innerHTML = '<button type="button" class="button button--ghost" aria-expanded="false">' + heading.innerHTML + '</svg></button>';
2424

2525
// Add appropriate aria role to the collapsible section
2626
heading.nextElementSibling.setAttribute('aria-hidden', 'true');

assets-src/styles/sass/60-advanced-components/_collapsibles.scss

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
width: 100%;
2828
}
2929

30+
// Decorative chevron
31+
&::after {
32+
block-size: rem(14);
33+
border-color: black;
34+
border-style: solid;
35+
border-width: 0 rem(4) rem(4) 0;
36+
content: "";
37+
inline-size: rem(14);
38+
margin-block-start: rem(4);
39+
transform: rotate(45deg);
40+
}
41+
3042
&:hover {
3143
text-decoration: underline; /* 1 */
3244
text-decoration-skip-ink: auto; // Not supported by Safari
@@ -38,20 +50,15 @@
3850
background-color: $focus-color;
3951
text-decoration: none;
4052
}
41-
42-
&[aria-expanded="false"] .angle-up {
43-
display: none;
44-
}
45-
46-
&[aria-expanded="true"] .angle-down {
47-
display: none;
48-
}
49-
50-
svg {
51-
flex-shrink: 0;
52-
}
5353
}
5454

55+
[data-heading="collapsibles"] button[aria-expanded="true"] {
56+
&::after {
57+
margin-block-start: rem(10);
58+
scale: -1;
59+
}
60+
}
61+
5562
[data-heading="collapsibles"] + * {
5663
&[aria-hidden="true"] {
5764
display: none;

public/dist/assets/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ let collapsibles = function () {
417417
// Loop through headings
418418
headingsArray.forEach(function (heading, index) {
419419
// Insert a button for opening/closing the collapsible section
420-
heading.innerHTML = '<button type="button" class="button--ghost" aria-expanded="false">' + heading.innerHTML + '<svg xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 320 512" class="icon icon--larger" focusable="false" aria-hidden="true" width="30px" height="30px"><path class="angle-down" d="M143 352.3L7 216.3c-9.4-9.4-9.4-24.6 0-33.9l22.6-22.6c9.4-9.4 24.6-9.4 33.9 0l96.4 96.4 96.4-96.4c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9l-136 136c-9.2 9.4-24.4 9.4-33.8 0z"/><path class="angle-up" d="M177 159.7l136 136c9.4 9.4 9.4 24.6 0 33.9l-22.6 22.6c-9.4 9.4-24.6 9.4-33.9 0L160 255.9l-96.4 96.4c-9.4 9.4-24.6 9.4-33.9 0L7 329.7c-9.4-9.4-9.4-24.6 0-33.9l136-136c9.4-9.5 24.6-9.5 34-.1z"/></svg></button>';
420+
heading.innerHTML = '<button type="button" class="button button--ghost" aria-expanded="false">' + heading.innerHTML + '</svg></button>';
421421

422422
// Add appropriate aria role to the collapsible section
423423
heading.nextElementSibling.setAttribute('aria-hidden', 'true');

0 commit comments

Comments
 (0)