Skip to content

Commit 8e12b10

Browse files
committed
Improve cheatsheet
1 parent 90d5eb1 commit 8e12b10

File tree

5 files changed

+92
-14
lines changed

5 files changed

+92
-14
lines changed

apps/components_guide_web/assets/css/app.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ html {
1010
@apply bg-gray-900;
1111
}
1212

13+
article a {
14+
text-decoration: underline;
15+
}
1316
article a:hover {
1417
text-decoration: underline;
1518
}

apps/components_guide_web/lib/components_guide_web/templates/accessibility_first_testing/index.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ topics = [
3636

3737
<div class="bg-white">
3838
<%= section "Topics", class: "container pt-8 pb-16 text-2xl" do %>
39-
<%= topic_article(title: "Landmarks and roles") do %>
39+
<%= topic_article(title: "Landmarks and roles", link: Routes.accessibility_first_testing_path(@conn, :show, "roles-cheatsheet")) do %>
4040
<p>Define what your elements are using a clear standard. Let your users quickly jump around the key parts of your page (better UX), and leverage those in your tests (better DX).</p>
4141
<% end %>
4242
<%= topic_article(title: "Widgets, Attributes & States") do %>

apps/components_guide_web/lib/components_guide_web/templates/accessibility_first_testing/roles-cheatsheet.html.eex

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
<%
2+
theme = %Theme{text_color: "blue"}
3+
%>
14
<header class="text-white" style="background: <%= header_background %>;">
25
<section class="container px-6 pt-6 pb-6">
36
<h1 class="mx-auto max-w-4xl text-4xl text-center font-bold leading-tight text-shadow">
4-
<%= "Roles Cheatsheet" %>
7+
<%= "Widgets Cheatsheet" %>
58
</h1>
69
<p class="mt-4 mx-auto max-w-3xl text-3xl text-center leading-snug italic text-yellow-100 text-shadow">
7-
<%= "Find the role and copy the tests for a particular UI widget." %>
10+
<%= "UI roles and their pre-written tests." %>
811
</p>
912
</section>
1013
</header>
@@ -17,15 +20,14 @@
1720
<li><%= link "Checkbox", to: "#checkbox" %>
1821
<li><%= link "Radio", to: "#radio" %>
1922
<li><%= link "Tab", to: "#tab" %>
23+
<li><%= link("List of roles 🔗", to: "https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques") %>
2024
</ul>
2125
</nav>
2226
<div class="ml-64">
23-
<section aria-label="Roles Cheatsheet" class="container px-4 pt-8 pb-16 text-2xl">
24-
25-
<%= link_to("List of roles", to: "https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques") %>
26-
27+
<section aria-label="Roles Cheatsheet" class="px-4 pt-8 pb-16 text-xl">
2728
<article>
28-
<h2 id="link" class="mb-2 text-4xl leading-normal text-teal-800">Link</h2>
29+
<%= theme |> Theme.h2("Link", id: "link") %>
30+
2931
<%=
3032
"""
3133
getByRole('link', { name: 'About' });
@@ -57,11 +59,68 @@
5759
<%=
5860
"""
5961
getByRole('checkbox', { name: 'Remember me' });
62+
63+
const rememberMe = getByRole('checkbox', { name: 'Remember me' });
64+
expect(rememberMe).toBeChecked();
65+
""" |> code_block(:js)
66+
%>
67+
68+
<h3>HTML example</h3>
69+
<%=
70+
"""
71+
<label><input type="checkbox">Remember me</label>
72+
""" |> code_block(:html)
73+
%>
74+
</article>
75+
76+
<article>
77+
<%= theme |> Theme.h2("Textbox", id: "textbox") %>
78+
79+
<h3>It has Bio text field</h3>
80+
<%=
81+
"""
82+
getByLabelText('Bio');
83+
""" |> code_block(:js)
84+
%>
85+
<%=
86+
"""
87+
<label>Bio<input></label>
88+
""" |> code_block(:html)
89+
%>
90+
91+
<h3>It has Bio text field</h3>
92+
<%=
93+
"""
94+
getByLabelText('Bio');
95+
""" |> code_block(:js)
96+
%>
97+
<%=
98+
"""
99+
<label>Bio<textarea></textarea></label>
100+
""" |> code_block(:html)
101+
%>
102+
103+
<h3>It is valid</h3>
104+
<%=
105+
"""
106+
expect(getByLabelText('Bio')).toBeValid();
107+
""" |> code_block(:js)
108+
%>
109+
<%=
110+
"""
111+
<label>Bio<textarea aria-invalid=false></textarea></label>
112+
""" |> code_block(:html)
113+
%>
114+
115+
<h3>It is invalid</h3>
116+
<%=
117+
"""
118+
expect(getByLabelText('Bio')).toBeInvalid();
60119
""" |> code_block(:js)
61120
%>
62121
<%=
63122
"""
64-
<label><input type=checkbox> Remember me</label>
123+
<label>Bio<textarea aria-invalid=true></textarea></label>
65124
""" |> code_block(:html)
66125
%>
67126
</article>
@@ -75,9 +134,9 @@
75134
%>
76135
<%=
77136
"""
78-
<label><input type=radio> Purple</label>
79-
<label><input type=radio> Blue</label>
80-
<label><input type=radio> Orange</label>
137+
<label><input type="radio">Purple</label>
138+
<label><input type="radio">Blue</label>
139+
<label><input type="radio">Orange</label>
81140
""" |> code_block(:html)
82141
%>
83142
</article>

apps/components_guide_web/lib/components_guide_web/templates/concepts/index.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<li>Isolated unit tests
2626
<li>Integration tests
2727
<li>Acceptance tests
28-
<li>Accessibility tests
28+
<li><%= link 'Accessibility-first tests', to: Routes.accessibility_first_testing_path(@conn, :index) %>
2929
</ul>
3030
<% end %>
3131

apps/components_guide_web/lib/components_guide_web/views/accessibility_first_testing_view.ex

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule ComponentsGuideWeb.AccessibilityFirstTestingView do
22
use ComponentsGuideWeb, :view
33
require EEx
44
use ComponentsGuideWeb.Snippets
5+
use Phoenix.HTML
56

67
def header_background do
78
Styling.linear_gradient("150grad", [
@@ -14,7 +15,13 @@ defmodule ComponentsGuideWeb.AccessibilityFirstTestingView do
1415
def topic_article(assigns, block) do
1516
~E"""
1617
<article class="mb-8">
17-
<h2 class="mb-2 text-4xl leading-normal text-teal-800"><%= @title %></h2>
18+
<h2 class="mb-2 text-4xl leading-normal text-teal-800">
19+
<%= if Keyword.has_key?(assigns, :link) do %>
20+
<%= link @title, to: @link %>
21+
<% else %>
22+
<%= @title %>
23+
<% end %>
24+
</h2>
1825
<%= block[:do] %>
1926
</article>
2027
"""
@@ -25,4 +32,13 @@ defmodule ComponentsGuideWeb.AccessibilityFirstTestingView do
2532
<pre><code class='<%= "lang-#{type}" %>'><%= code %></code></pre>
2633
"""
2734
end
35+
36+
defmodule Theme do
37+
defstruct text_color: "blue"
38+
39+
def h2(theme = %Theme{}, content, attrs) do
40+
class = "mb-2 text-4xl leading-normal text-#{theme.text_color}-800"
41+
content_tag(:h2, content, [ {:class, class} | attrs ])
42+
end
43+
end
2844
end

0 commit comments

Comments
 (0)