Skip to content

Commit 344276e

Browse files
committed
Add Link vs Button
1 parent 7171990 commit 344276e

File tree

3 files changed

+107
-40
lines changed

3 files changed

+107
-40
lines changed

apps/components_guide_web/assets/css/app.css

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,56 @@
99
@import "../node_modules/nprogress/nprogress.css";
1010

1111
:root {
12-
@apply bg-gray-900;
12+
@apply bg-gray-900;
1313

14-
--link-color: currentColor;
14+
--link-color: currentColor;
1515

16-
--size-xs: .75rem;
17-
--size-sm: .875rem;
18-
--size-base: 1rem;
19-
--size-lg: 1.125rem;
20-
--size-xl: 1.25rem;
21-
--size-2xl: 1.5rem;
22-
--size-3xl: 1.875rem;
23-
--size-4xl: 2.25rem;
24-
--size-5xl: 3rem;
25-
--size-6xl: 4rem;
16+
--size-xs: 0.75rem;
17+
--size-sm: 0.875rem;
18+
--size-base: 1rem;
19+
--size-lg: 1.125rem;
20+
--size-xl: 1.25rem;
21+
--size-2xl: 1.5rem;
22+
--size-3xl: 1.875rem;
23+
--size-4xl: 2.25rem;
24+
--size-5xl: 3rem;
25+
--size-6xl: 4rem;
2626
}
2727

2828
[hidden] {
29-
display: none !important;
29+
display: none !important;
3030
}
3131

3232
article a:not(nav *) {
33-
text-decoration: underline;
33+
text-decoration: underline;
3434
}
3535
article a:hover {
36-
text-decoration: underline;
36+
text-decoration: underline;
3737
}
3838
article figcaption {
3939
font-style: italic;
4040
}
4141

4242
.a\{font-bold\} a {
43-
font-weight: bold;
43+
font-weight: bold;
4444
}
4545

4646
a {
47-
color: var(--link-color);
48-
padding: var(--link-padding);
49-
text-decoration: var(--link-decoration);
47+
color: var(--link-color);
48+
padding: var(--link-padding);
49+
text-decoration: var(--link-decoration);
5050
}
5151
a:hover {
52-
text-decoration: var(--hover\:links-decoration);
52+
text-decoration: var(--hover\: links-decoration);
5353
}
5454

55-
h1, h2, h3, p, li, table {
55+
h1,
56+
h2,
57+
h3,
58+
p,
59+
li,
60+
table,
61+
blockquote {
5662
margin-left: var(--item-spacing-left);
5763
margin-right: var(--item-spacing-right);
5864
}
@@ -87,6 +93,13 @@ table {
8793
padding: var(--code-spacing);
8894
border-radius: var(--code-radius);
8995
}
96+
blockquote {
97+
--link-decoration: underline;
98+
margin: var(--blockquote-spacing-outer);
99+
padding: var(--blockquote-spacing-inner);
100+
font-style: var(--blockquote-font-style);
101+
background: var(--blockquote-background);
102+
}
90103
hr {
91104
margin: var(--separator-spacing);
92105
color: var(--separator-color);
@@ -96,7 +109,8 @@ input {
96109
outline: none;
97110
}
98111

99-
:not(pre) > code, pre {
112+
:not(pre) > code,
113+
pre {
100114
color: white;
101115
background-color: #011627;
102116
}
@@ -116,6 +130,10 @@ input {
116130
--table-spacing: var(--size-xl) 0;
117131
--code-spacing: 0 0.1875em;
118132
--code-radius: 0.125em;
133+
--blockquote-spacing-outer: 1rem 0rem;
134+
--blockquote-spacing-inner: 1rem;
135+
--blockquote-font-style: italic;
136+
--blockquote-background: rgba(255, 255, 255, 0.1);
119137
--separator-spacing: var(--size-5xl) 0;
120138
--separator-color: currentColor;
121139
}
@@ -125,23 +143,23 @@ input {
125143
}
126144

127145
.container {
128-
@apply max-w-5xl mx-auto px-6;
146+
@apply max-w-5xl mx-auto px-6;
129147
}
130148

131149
.nums-tabular {
132-
font-variant-numeric: tabular-nums;
150+
font-variant-numeric: tabular-nums;
133151
}
134152

135153
.text-shadow {
136-
text-shadow: 0.0625em 0.0625em 0.125em rgba(0,0,0,0.25);
154+
text-shadow: 0.0625em 0.0625em 0.125em rgba(0, 0, 0, 0.25);
137155
}
138156

139157
ul:not([class]) {
140-
list-style: disc;
141-
padding-left: 1em;
158+
list-style: disc;
159+
padding-left: 1em;
142160
}
143161
ul:not([class]) > li > ul:not([class]) {
144-
@apply pl-8;
162+
@apply pl-8;
145163
}
146164

147165
ol:not([class]) {
@@ -150,13 +168,13 @@ ol:not([class]) {
150168
}
151169

152170
/* Navigation links */
153-
a[aria-current=page][class*="hover\:border-"] {
154-
border-color: currentColor;
171+
a[aria-current="page"][class*="hover\:border-"] {
172+
border-color: currentColor;
155173
}
156174

157-
[phx-hook=SwatchInput] {
158-
user-select: none;
159-
cursor: default;
175+
[phx-hook="SwatchInput"] {
176+
user-select: none;
177+
cursor: default;
160178
}
161179

162180
/* @import "./phoenix.css"; */

apps/components_guide_web/lib/components_guide_web/templates/accessibility_first/_nav.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<nav class="pt-6 pb-4">
22
<ul y-y x-x=md class="text-lg font-bold text-shadow" style="--link-padding: 0.75em">
3-
<li><%= link("Intro", to: '/accessibility-first') %>
3+
<li><%= link("Why?", to: '/accessibility-first') %>
44
<li><%= link("Navigation", to: '/accessibility-first/navigation') %>
55
<li><%= link("Roles", to: '/accessibility-first/roles') %>
66
<li><%= link("Accessible Name", to: '/accessibility-first/accessible-name') %>
Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
# Navigation elements
22

3+
## Link vs Button
4+
5+
Links are the ‘secret ingredient’ of the web. They take web pages from being standalone documents to being part of a living, collaborative medium.
6+
7+
As a web author, it’s easy to mix up links and buttons, especially when everything is styled to look like a rounded capsule. However, there are clear rules you can follow for when to use links and when to use buttons.
8+
9+
Here’s what users like to do with links:
10+
11+
- They can open a link in a new tab.
12+
- They can share that link with someone else so they can arrive at the same place.
13+
- They can bookmark that link for later.
14+
15+
Let’s see how the specs describe links:
16+
17+
> [WAI-ARIA](https://www.w3.org/TR/wai-aria-1.1/#link) — An interactive reference to an internal or external resource that, when activated, causes the user agent to navigate to that resource.
18+
19+
So how are buttons different?
20+
21+
Clicking a button usually produces a change of some sort. For example, a Checkout action should be a button and not a link, because that action changes the state of the shopping cart. It makes little sense to be able to look at the shopping cart before it was checked out.
22+
23+
In contrast to a link:
24+
25+
- The user shouldn’t be able to open Checkout in a new tab.
26+
- The user can’t share Checkout with someone else.
27+
- The user can’t bookmark Checkout for later.
28+
29+
> [WAI-ARIA Practices](https://www.w3.org/TR/wai-aria-practices/#button) — A button is a widget that enables users to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation.
30+
31+
Let’s look the example of an online store, and categorize things into links or buttons:
32+
33+
- The Product Name _links_ to the page dedicated to this product.
34+
- The Add to Wishlist _button_ performs the add to wishlist action.
35+
- The Checkout _button_ changes the state of the shopping cart.
36+
- The Product Image _link_ opens the product photo gallery.
37+
- The More Details _button_ expands to show the full specifications of the product.
38+
39+
----
40+
41+
In short, buttons **perform actions** and links **navigate somewhere**. Links have URLs that can be shared or copied, and buttons cannot be shared.
42+
43+
Every element of a UI mockup should be very clear which model they use. How these elements work is part of the design.
44+
45+
----
46+
347
## Link
448

549
```html
@@ -10,22 +54,20 @@
1054
const aboutLink = screen.getByRole('link', { name: 'About' });
1155
```
1256

13-
### Current link
57+
### When the link is the current page
1458

1559
```html
1660
<a href="/about" aria-current=page>About</a>
1761
```
1862

1963
```ts
64+
const aboutLink = screen.getByRole('link', { name: 'About' });
2065
expect(aboutLink).toHaveAttribute('aria-current', 'page');
2166
```
2267

23-
## Navigation
68+
----
2469

25-
```ts
26-
const primaryNav = screen.getByRole('navigation', { name: 'Primary' });
27-
const navLinks = getAllByRole(primaryNav, 'link');
28-
```
70+
## Navigation
2971

3072
```html
3173
<nav aria-label=Primary>
@@ -36,3 +78,10 @@ const navLinks = getAllByRole(primaryNav, 'link');
3678
</ul>
3779
</nav>
3880
```
81+
82+
```ts
83+
const primaryNav = screen.getByRole('navigation', { name: 'Primary' });
84+
const navLinks = getAllByRole(primaryNav, 'link');
85+
86+
expect(navLinks).toHaveLength(3);
87+
```

0 commit comments

Comments
 (0)