Skip to content

Commit 7341c81

Browse files
authored
Merge pull request #150 from w3c/feature/simplify-globalnav-markup
Feature/simplify globalnav markup
2 parents 90b3baf + 3fedc1d commit 7341c81

File tree

20 files changed

+412
-316
lines changed

20 files changed

+412
-316
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/js/main/navigation.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ const navigation = function(menu, options) {
197197
// Insert a "back" button
198198
const backButton = document.createElement('button');
199199
backButton.setAttribute('data-button', 'mobile-back');
200-
backButton.setAttribute('class', 'button button--ghost u-full-width with-icon--before with-icon--larger');
201-
backButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512" height="16" width="16" class="icon icon--submenu" focusable="false" aria-hidden="true" fill="currentColor">' +
202-
'<path d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"/>' +
203-
'</svg>' + translate.translate('backToMainMenu', languageCode);
200+
backButton.setAttribute('class', 'button button--ghost u-full-width');
201+
backButton.innerHTML = translate.translate('backToMainMenu', languageCode);
204202
if (settings.submenuIntro === true) {
205203
subMenu.parentNode.insertBefore(backButton, subMenu.parentNode.children[0]);
206204
} else subMenu.parentNode.insertBefore(backButton, subMenu);

assets-src/styles/sass/30-base/_lists.scss

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,16 @@
22
#Lists
33
\*------------------------------------*/
44

5-
/**
6-
Remove default list styles on lists with a class name (e.g. 'nav-list')
7-
*/
8-
ol[class],
9-
ul[class] {
10-
list-style: none;
11-
padding: 0;
12-
}
13-
14-
ul:not([class]),
15-
ol:not([class]),
16-
ol.counter {
5+
ul,
6+
ol {
177
margin-block-end: 1em;
188
margin-block-start: 1em;
199
padding-inline-start: 2.4em;
2010

2111
> * + *,
2212
li ul,
2313
li ol {
24-
margin-top: 0.75em;
14+
margin-block-start: 0.75em;
2515
}
2616
}
2717

@@ -32,11 +22,25 @@ ol.counter {
3222
}
3323

3424

35-
// No bullets or numbering
25+
/**
26+
Remove bullets, margin and padding from lists inside a <nav> element, and lists with the
27+
'.clean-list' class/. Note that that this may remove list semantics in some circumstances in
28+
some WebKit browsers. See https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html
29+
If it's important that the number of items in a list is announced, add role="list" to the <ul> / <ol>
30+
*/
31+
nav ul,
32+
nav ol,
3633
.clean-list {
37-
li {
38-
display: block;
39-
}
34+
list-style: none;
35+
margin: 0;
36+
padding: 0;
37+
38+
li,
39+
ol,
40+
ul {
41+
margin: 0;
42+
padding: 0;
43+
}
4044
}
4145

4246

@@ -52,12 +56,12 @@ dl {
5256
}
5357

5458
dd + dt {
55-
margin-top: 0.5em;
59+
margin-block-start: 0.5em;
5660
}
5761

5862
dt + dd,
5963
dd + dd {
60-
margin-top: 0.25em;
64+
margin-block-start: 0.25em;
6165
}
6266
}
6367

@@ -95,7 +99,7 @@ dl.grid {
9599
dd + dt,
96100
dt + dd,
97101
dd + dd {
98-
margin-top: 0;
102+
margin-block-start: 0;
99103
}
100104

101105
dt {

assets-src/styles/sass/50-core-components/_navigation.scss

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
li.top-nav-item + li.top-nav-item {
4949
@include mq($max-width) {
50-
margin-inline-start: rem(4);
50+
margin-inline-start: rem(8);
5151
}
5252
}
5353

@@ -80,7 +80,24 @@ li.top-nav-item + li.top-nav-item {
8080
}
8181

8282
.global-nav__inner .top-nav-item > .nav-link {
83-
font-weight: $emphasis;
83+
font-weight: $emphasis;
84+
}
85+
86+
// Add chevron to links with children - visually hide but retain space.
87+
.global-nav__inner .has-children > .nav-link {
88+
align-items: center;
89+
display: flex;
90+
91+
&::after {
92+
block-size: rem(7);
93+
border-color: black;
94+
border-style: solid;
95+
border-width: 0 rem(2) rem(2) 0;
96+
content: "";
97+
inline-size: rem(7);
98+
margin-inline-start: rem(12);
99+
visibility: hidden;
100+
}
84101
}
85102

86103
.logo-link {

assets-src/styles/sass/50-core-components/_toc.scss

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
\*------------------------------------*/
44

55
.toc + * {
6-
margin-top: rem(30);
6+
margin-block-start: rem(30);
77

88
@include mq($max-width) {
9-
margin-top: rem(80);
9+
margin-block-start: rem(80);
1010
}
1111
}
1212

@@ -15,22 +15,22 @@
1515
font-weight: normal;
1616
}
1717

18-
.toc ul {
19-
border-left: solid 3px $deep-yellow;
20-
padding-left: rem(15);
18+
// Only apply the border to the top level list
19+
.toc > ul {
20+
border-inline-start: solid 3px $deep-yellow;
2121
}
2222

23-
[dir="rtl"] {
24-
.toc ul {
25-
border-left: 0;
26-
border-right: solid 3px $deep-yellow;
27-
padding-left: 0;
28-
padding-right: rem(15);
29-
}
23+
.toc ul {
24+
line-height: 1em;
25+
padding-inline-start: rem(15);
26+
27+
ul {
28+
list-style: circle inside;
29+
padding-inline-start: rem(30);
30+
}
3031
}
3132

3233
.toc ul a {
3334
display: inline-block;
34-
padding-bottom: rem(10);
35-
padding-top: rem(10);
35+
padding-block: rem(10);
3636
}

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
line-height: calc(27 / 18);
1616
justify-content: space-between;
1717
margin-top: 0;
18-
padding: 0;
18+
padding: rem(3);
1919
width: 100%;
2020

2121
> span {
@@ -27,6 +27,19 @@
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+
margin-inline-end: rem(2);
40+
transform: rotate(45deg);
41+
}
42+
3043
&:hover {
3144
text-decoration: underline; /* 1 */
3245
text-decoration-skip-ink: auto; // Not supported by Safari
@@ -38,20 +51,15 @@
3851
background-color: $focus-color;
3952
text-decoration: none;
4053
}
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-
}
5354
}
5455

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

assets-src/styles/sass/60-advanced-components/_disclosure-widget.scss

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@
1515
[data-toggle="true"] {
1616
@include txt-pluto;
1717
align-items: center;
18+
display: inline-flex;
1819
font-weight: bold;
1920

20-
svg {
21-
pointer-events: none;
22-
}
21+
// Decorative chevron
22+
&::after {
23+
block-size: rem(7);
24+
border-color: black;
25+
border-style: solid;
26+
border-width: 0 rem(2) rem(2) 0;
27+
content: "";
28+
inline-size: rem(7);
29+
margin-block-start: rem(-3);
30+
margin-inline-end: rem(3);
31+
margin-inline-start: rem(12);
32+
transform: rotate(45deg);
33+
}
2334

2435
&:hover {
2536
box-shadow: 0 0 4px 2px rgba(84,84,84,0.25);
@@ -33,19 +44,16 @@
3344
}
3445

3546
[data-toggle="true"][aria-expanded="false"] {
36-
.angle-up {
37-
display: none;
38-
}
39-
4047
+ * {
4148
display: none;
4249
}
4350
}
4451

4552
[data-toggle="true"][aria-expanded="true"] {
46-
.angle-down {
47-
display: none;
48-
}
53+
&::after {
54+
margin-block-start: rem(4);
55+
scale: -1;
56+
}
4957

5058
+ * {
5159
display: block;

0 commit comments

Comments
 (0)