Skip to content

Commit 873f14e

Browse files
committed
WIP
1 parent a767d61 commit 873f14e

File tree

4 files changed

+91
-30
lines changed

4 files changed

+91
-30
lines changed

.vitepress/theme/custom.css

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,3 @@
99
--vp-c-text: #ffffff;
1010
--vp-c-bg-alt: #121212;
1111
}
12-
13-
#author {
14-
display: flex;
15-
align-items: center;
16-
}
17-
#author img {
18-
width: 50px;
19-
height: 50px;
20-
border-radius: 50%;
21-
background: #ffffff;
22-
}
23-
#author .author-name {
24-
display: flex;
25-
flex-direction: column;
26-
align-items: flex-start;
27-
margin-left: 10px;
28-
font-size: 1rem;
29-
line-height: 1.2;
30-
}

index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,24 @@ hero:
1111
text: Get Started!
1212
link: /wai-aria
1313
---
14+
15+
<style>
16+
#author {
17+
display: flex;
18+
align-items: center;
19+
}
20+
#author img {
21+
width: 50px;
22+
height: 50px;
23+
border-radius: 50%;
24+
background: #ffffff;
25+
}
26+
#author .author-name {
27+
display: flex;
28+
flex-direction: column;
29+
align-items: flex-start;
30+
margin-left: 10px;
31+
font-size: 1rem;
32+
line-height: 1.2;
33+
}
34+
</style>

semantic-html.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,4 @@ function ListItem({ item }) {
7070

7171
## Headings Hierarchy
7272

73-
...
74-
75-
## Landmark Elements
76-
77-
Use landmark elements and roles, such as `<main>` and `<aside>`, to demarcate page regions as assistive technology allow the user to quickly navigate to these sections.
78-
79-
Read more about the use of these elements to enhance accessibility here:
80-
81-
- [Accessible Landmarks](https://www.scottohara.me/blog/2018/03/03/landmarks.html)
73+
Semantic structure is created with `<h1>`-`<h6>` headings, landmarks such as `<main>`, `<nav>`, `<footer>`, `<section>` (with unique labels), content markup including `<ul>` and `<ol>` lists, and more. These are incredibly important for people who rely on AT to understand the structure of a page.

wai-aria.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ outline: "deep"
44

55
# WAI-ARIA
66

7-
The [Web Accessibility Initiative - Accessible Rich Internet Applications](https://www.w3.org/WAI/intro/aria) document contains techniques for building fully accessible JavaScript widgets.
7+
The [Web Accessibility Initiative - Accessible Rich Internet Applications](https://www.w3.org/WAI/intro/aria) (WAI-ARIA) document contains techniques for building fully accessible JavaScript widgets and web applications. It defines a set of attributes to help make web content and web applications more accessible to people with disabilities.
88

9-
Note that all `aria-*` HTML attributes are fully supported in JSX. Whereas most DOM properties and attributes in React are camelCased, these attributes should be hyphen-cased (also known as kebab-case, lisp-case, etc) as they are in plain HTML:
9+
Note that all `aria-*` HTML attributes are fully supported in JSX. Whereas most DOM properties and attributes in React are camelCased, these attributes should be hyphen-cased (also known as kebab-case, lisp-case, etc.) as they are in plain HTML:
1010

1111
```tsx
1212
<input
@@ -18,3 +18,70 @@ Note that all `aria-*` HTML attributes are fully supported in JSX. Whereas mos
1818
name="name"
1919
/>
2020
```
21+
22+
## How should we use these ARIA attributes?
23+
24+
While ARIA attributes are powerful tools for enhancing accessibility, it's important to use them correctly. The primary goal is to provide semantic information to assistive technologies, like screen readers, where native HTML might not be sufficient.
25+
26+
### Prioritize Native HTML Elements
27+
28+
Before resorting to ARIA, always try to use native HTML elements for their built-in semantics and accessibility features. For example, the `<label>` element is the best and preferred way to label form controls:
29+
30+
```html
31+
<label for="nameInput">Name:</label>
32+
<input type="text" id="nameInput" name="name" />
33+
```
34+
35+
Linking a `label` to an input using the `for` attribute (pointing to the input's `id`) is the most robust way to ensure the input is properly labeled.
36+
37+
### When to Use ARIA Attributes
38+
39+
ARIA attributes should be used when native HTML doesn't provide the necessary semantics or when you are building custom widgets that don't have native HTML equivalents. Here are some common ARIA attributes and how to use them, inspired by insights from accessibility specialists:
40+
41+
1. **`aria-label`**:
42+
43+
- **Use Case**: Provides an accessible name for an element when there is no visible text label on the screen. This is common for icon buttons (e.g., a search button with only a magnifying glass icon) or other interactive elements where a visible label would be redundant or clunky.
44+
- **Example (from above)**: `aria-label={labelText}` ensures that even if there's no visible label text directly associated with the input, a screen reader will announce the value of `labelText`.
45+
- **Important**: The `aria-label` string will be announced by screen readers along with the element's role (e.g., "Search, button" or "Name, edit text").
46+
47+
2. **`aria-labelledby`**:
48+
49+
- **Use Case**: Provides an accessible name by referencing the `id`(s) of other elements on the page that serve as the label. This is useful when the labeling text is already present visually but isn't directly associated with the input using a `<label for="...">` tag, or when a label is composed of multiple text elements.
50+
- **Example**:
51+
```tsx
52+
<div id="billing">Billing Address</div>
53+
// ... other elements ...
54+
<label id="streetLabel">Street:</label>
55+
<input type="text" aria-labelledby="billing streetLabel" />
56+
```
57+
In this case, a screen reader might announce "Billing Address Street: edit text". The referenced IDs are space-separated.
58+
59+
3. **`aria-describedby`**:
60+
61+
- **Use Case**: Provides additional, non-essential information or a description for an element. This description is typically announced _after_ the element's label and role. It's useful for instructions, format requirements, or error messages.
62+
- **Example**:
63+
```tsx
64+
<label for="password">Password:</label>
65+
<input type="password" id="password" aria-describedby="passwordHint" />
66+
<p id="passwordHint">Must be at least 8 characters long.</p>
67+
```
68+
A screen reader would first announce the label ("Password, edit text, protected") and then the description ("Must be at least 8 characters long.").
69+
- **Crucial Note**: `aria-describedby` provides a _description_, not a label. You still need to ensure the element has a proper accessible name via `<label>`, `aria-label`, or `aria-labelledby`.
70+
71+
4. **`aria-required`**:
72+
- **Use Case**: Indicates to assistive technologies that user input is required on an element before a form can be submitted.
73+
- **Example (from above)**: `aria-required="true"` will inform a screen reader user that the input field must be filled. This often complements visual indicators like asterisks.
74+
75+
### What to Avoid
76+
77+
- **`aria-details`**: While it exists to point to more detailed rich content, its screen reader support is currently poor, so it should generally not be relied upon for essential labeling or descriptive information.
78+
- **`aria-description`**: This attribute is not currently part of the official ARIA specification and lacks browser and assistive technology support, making it unusable.
79+
80+
### General Principles
81+
82+
- **Don't override native semantics unless necessary**: If an HTML element already has the correct role, state, or property, you don't need to add ARIA to reiterate it.
83+
- **Test with assistive technologies**: The best way to ensure your ARIA attributes are working correctly is to test your interface using screen readers (e.g., NVDA, JAWS, VoiceOver) and other accessibility tools.
84+
85+
By understanding and correctly applying these ARIA attributes, along with prioritizing native HTML, you can significantly improve the accessibility of your web applications for all users.
86+
87+

0 commit comments

Comments
 (0)