Skip to content

Commit 315fd5a

Browse files
committed
Improve quick links nav menu
1 parent 8400300 commit 315fd5a

File tree

6 files changed

+136
-14
lines changed

6 files changed

+136
-14
lines changed

apps/components_guide_web/assets/css/app.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@ ol:not([class]) {
259259
padding-left: 1em;
260260
}
261261

262+
/* GitHub Elements */
263+
264+
/* https://github.com/github/details-menu-element */
265+
summary[aria-haspopup="menu"] {
266+
display: list-item;
267+
list-style: none;
268+
}
269+
summary[aria-haspopup="menu"]:before, summary[aria-haspopup="menu"]::-webkit-details-marker {
270+
display: none;
271+
}
272+
/* Makes menu buttons take over the entire viewport when open, allowing easy taps */
273+
details[open] summary[aria-haspopup="menu"]:before {
274+
position: fixed;
275+
top: 0;
276+
right: 0;
277+
bottom: 0;
278+
left: 0;
279+
z-index: 80;
280+
display: block;
281+
cursor: default;
282+
content: " ";
283+
background: transparent;
284+
}
285+
262286
/* Navigation links */
263287
a[aria-current="page"][class*="hover\:border-"] {
264288
border-color: currentColor;

apps/components_guide_web/assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"license": "MIT",
44
"scripts": {
55
"deploy": "webpack --mode production",
6-
"watch": "webpack --mode development --watch"
6+
"watch": "NODE_ENV=development webpack --mode development --watch"
77
},
88
"dependencies": {
99
"@hotwired/turbo": "^7.0.0-beta.4",
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Refactoring Accessibility
2+
3+
<script type=module>
4+
import * as DOMTesting from "https://cdn.skypack.dev/@testing-library/dom";
5+
6+
function* surroundingSourceElements(el) {
7+
let prev = el;
8+
while (prev = prev.previousElementSibling) {
9+
if (prev.matches('h1, h2, h3, h4')) break;
10+
if (prev.matches('pre.language-html')) yield { type: 'html', code: prev.textContent, el: prev };
11+
if (prev.matches('pre.language-javascript')) yield { type: 'javascript', code: prev.textContent, el: prev };
12+
}
13+
14+
let next = el;
15+
while (next = next.nextElementSibling) {
16+
if (next.matches('h1, h2, h3, h4')) break;
17+
if (next.matches('pre.language-html')) yield { type: 'html', code: next.textContent, el: next };
18+
if (next.matches('pre.language-javascript')) yield { type: 'javascript', code: next.textContent, el: next };
19+
}
20+
}
21+
22+
const outputEls = document.querySelectorAll('article output');
23+
24+
function classNamesFor(index) {
25+
return ['border-yellow-500', 'border-green-500 border-dotted', 'border-purple-500 border-double'][index].split(' ');
26+
}
27+
28+
for (const outputEl of outputEls.values()) {
29+
const div = outputEl.appendChild(document.createElement('div'));
30+
div.classList.add('p-4');
31+
32+
let javascriptIndex = 0;
33+
const sources = surroundingSourceElements(outputEl);
34+
for (const source of sources) {
35+
const { type, code, el } = source;
36+
37+
console.log('source', source);
38+
39+
if (type === 'html') {
40+
div.innerHTML = code;
41+
}
42+
43+
if (type === 'javascript') {
44+
const classNames = classNamesFor(javascriptIndex);
45+
46+
el.classList.add('border-l-4', ...classNames);
47+
48+
const screen = DOMTesting.within(div);
49+
const testFunction = new Function('screen', `return ${code}`);
50+
[].concat(testFunction(screen)).forEach(el => el.classList.add('border-4', ...classNames));
51+
52+
javascriptIndex++;
53+
}
54+
}
55+
}
56+
</script>
57+
58+
## Headings
59+
60+
- When to use `<h1>`?
61+
- Examples from news websites of their hierarchy
62+
63+
Here’s an example from The Economist:
64+
65+
```html
66+
<header>
67+
<h1>
68+
<span>
69+
Silent sigh
70+
</span>
71+
<br>
72+
<span itemprop="headline">
73+
South Korea is pushing America for new talks with the North
74+
</span>
75+
</h1>
76+
<p itemprop="description">
77+
The 70-year stalemate between the two Koreas is unlikely to break without fresh diplomacy
78+
</p>
79+
</header>
80+
```
81+
82+
<output></output>
83+
84+
```javascript
85+
screen.getByRole('heading');
86+
```
87+
88+
## Navigation
89+
90+
- Before: `class="current"`
91+
- After: `aria-current="page"`
92+
93+
## Tooltip
94+
95+
- Before: interactive tooltip that appears only after clicking a very small target
96+
- After: description hint text that is always shown, with `aria-describedby`

apps/components_guide_web/lib/components_guide_web/templates/layout/_banner.html.eex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
<%= search_form() %>
99
</div>
1010
<hr class="mx-auto">
11-
<details class="relative" data-links="block p-3">
12-
<summary>Jump to</summary>
13-
<ul class="absolute top-full right-0 flex flex-col bg-gray-900">
14-
<li><%= link("Accessibility First", to: '/accessibility-first') %>
15-
<li><%= link("React + TypeScript", to: '/react+typescript') %>
16-
<li><%= link("React + TypeScript", to: '/react+typescript') %>
17-
<li><%= link("Composable Systems", to: '/composable-systems') %>
18-
</ul>
11+
<details class="relative" data-links="block p-3 underline-on-hover">
12+
<summary>Quick links</summary>
13+
<details-menu role="menu" class="absolute top-full right-0 flex flex-col text-sm whitespace-nowrap bg-gray-900 rounded shadow-lg">
14+
<%= link("Accessibility First", to: '/accessibility-first') %>
15+
<%= link("React + TypeScript", to: '/react+typescript') %>
16+
<%= link("Web Standards", to: '/web-standards') %>
17+
<%= link("Composable Systems", to: '/composable-systems') %>
18+
</details-menu>
1919
</details>
2020
<ul class="h-full grid grid-rows-2 md:grid-cols-3 flex flex-col md:flex-row justify-around items-stretch tracking-wide">
2121
<% if false do %>

apps/components_guide_web/lib/components_guide_web/templates/layout/root.html.leex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<%= live_title_tag assigns[:page_title] || "Guides to React, Accessibility, Modern CSS, TypeScript", suffix: " · Components.Guide" %>
99
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
1010
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/RoyalIcing/tela@2d421cafc1ea99fab91aa4fcbf3b554160bcada5/tela.css"/>
11+
12+
<script type="module">
13+
import githubDetailsMenuElement from 'https://cdn.skypack.dev/@github/details-menu-element';
14+
</script>
1115

1216
<%= if @conn.path_info == [] do %>
1317
<meta property="og:type" content="website">

config/dev.exs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ config :components_guide_web, ComponentsGuideWeb.Endpoint,
1414
reloadable_apps: [:components_guide, :components_guide_web],
1515
check_origin: false,
1616
watchers: [
17-
node: [
18-
"node_modules/webpack/bin/webpack.js",
19-
"--mode",
20-
"development",
21-
"--watch-options-stdin",
17+
npm: [
18+
"run",
19+
"watch",
2220
cd: Path.expand("../apps/components_guide_web/assets", __DIR__)
2321
]
2422
]

0 commit comments

Comments
 (0)