Skip to content

Commit 64ede0f

Browse files
committed
fix(a11y): add explicit imports, title props, and star rating semantics in demo pages
- Add explicit imports for Base layout and Icon component to replace implicit globals; makes component contracts clear and auditable - Fix variable name: _icon -> icon so the runtime reference resolves - Add title prop to standalone icons so they are exposed as role='img' with an accessible name to screen readers (WCAG 1.1.1) - Wrap star icons in <figure aria-label='Rating: 4 out of 5 stars'> with a visually-hidden <figcaption> so the group meaning is communicated to AT users (WCAG 1.1.1, 1.3.1) - Add .visually-hidden utility class following the standard SR-only clip pattern
1 parent eaa59a9 commit 64ede0f

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

demo/src/pages/index.astro

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
2-
const _icon = "adjustment";
2+
import Base from "../layouts/base.astro";
3+
import { Icon } from "@dallay/astro-icon/components";
4+
5+
const icon = "adjustment";
36
---
47

58
<Base>
@@ -12,6 +15,7 @@ const _icon = "adjustment";
1215

1316
<article>
1417
<h2>Local Icons</h2>
18+
<!-- Decorative icons: aria-hidden handled automatically by Icon component -->
1519
<Icon size={24} name="adjustment" />
1620
<Icon size={24} name={icon} />
1721
<Icon size={24} name="annotation" />
@@ -30,16 +34,18 @@ const _icon = "adjustment";
3034
render it here!
3135
</p>
3236
</article>
37+
3338
<!-- Pull your icon from the default remote service -->
34-
<Icon size={32} name="ic:baseline-account-box" />
35-
<Icon size={64} name="ic:baseline-account-box" />
36-
<Icon size={80} name="ic:baseline-account-box" />
37-
38-
<Icon size={24} name="ic:baseline-directions-run" />
39-
<Icon size={64} name="fe:building" />
40-
<Icon size={64} name="ri:aliens-fill" />
41-
<Icon name="bi:stars" />
42-
<Icon name="ic:outline-star" />
39+
<!-- Meaningful icons: title prop exposes them as role="img" to screen readers -->
40+
<Icon size={32} name="ic:baseline-account-box" title="Account box" />
41+
<Icon size={64} name="ic:baseline-account-box" title="Account box" />
42+
<Icon size={80} name="ic:baseline-account-box" title="Account box" />
43+
44+
<Icon size={24} name="ic:baseline-directions-run" title="Running directions" />
45+
<Icon size={64} name="fe:building" title="Building" />
46+
<Icon size={64} name="ri:aliens-fill" title="Alien" />
47+
<Icon name="bi:stars" title="Stars" />
48+
<Icon name="ic:outline-star" title="Star" />
4349
</Base>
4450

4551
<style lang="css">

demo/src/pages/map.astro

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
---
2+
import Base from "../layouts/base.astro";
3+
import { Icon } from "@dallay/astro-icon/components";
24
---
35

46
<Base>
57
<h1>Welcome to Astro Icon!</h1>
68

7-
{Array.from({ length: 5 }).map(() => <Icon name="ic:outline-star" />)}
9+
<!--
10+
Star rating example: wrap the group in a <figure> with a <figcaption>
11+
so screen readers understand the collective meaning (WCAG 1.1.1 / 1.3.1).
12+
Each Icon is decorative within the group — aria-hidden is set automatically.
13+
-->
14+
<figure aria-label="Rating: 4 out of 5 stars">
15+
{Array.from({ length: 5 }, (_, i) => (
16+
<Icon
17+
name="ic:outline-star"
18+
title={i < 4 ? `Star ${i + 1}` : `Empty star ${i + 1}`}
19+
/>
20+
))}
21+
<figcaption class="visually-hidden">4 out of 5 stars</figcaption>
22+
</figure>
823
</Base>
924

1025
<style lang="css">
@@ -14,4 +29,17 @@
1429
[data-icon="ic:outline-star"]:last-of-type {
1530
color: lightgray;
1631
}
32+
33+
/* Visually hidden but available to assistive technologies (WCAG 1.3.1) */
34+
.visually-hidden {
35+
position: absolute;
36+
width: 1px;
37+
height: 1px;
38+
padding: 0;
39+
margin: -1px;
40+
overflow: hidden;
41+
clip: rect(0, 0, 0, 0);
42+
white-space: nowrap;
43+
border: 0;
44+
}
1745
</style>

0 commit comments

Comments
 (0)