@easy-web/content-blocks 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -17
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/Header.astro +16 -3
- package/src/components/HeaderCentered.astro +16 -3
- package/src/components/HeaderFlyout.astro +16 -3
- package/src/components/HeaderHideOnScroll.astro +16 -3
- package/src/components/PageShell.astro +85 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @easy-web/content-blocks
|
|
2
2
|
|
|
3
|
-
Reusable Astro content-block components for the
|
|
3
|
+
Reusable Astro content-block components for the ismaili.de web ecosystem. Twenty-eight pure-Astro components covering page chrome (`PageShell`, Header, Footer, ThemeToggle, LanguageSwitch), hero/CTA/contact sections, cards and grids, a CMS-driven gallery system with six variants, blog post cards, legal-page layouts, banners, and styled prose. All components use the `--ew-*` design tokens from `@easy-web/theme-core`; no styling system of their own.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -43,9 +43,11 @@ The package's `package.json` exports map declares `./components/*` → `./src/co
|
|
|
43
43
|
// src/layouts/Base.astro
|
|
44
44
|
import '@easy-web/theme-core/tokens.css';
|
|
45
45
|
import { noFlashScript } from '@easy-web/theme-core';
|
|
46
|
+
import PageShell from '@easy-web/content-blocks/components/PageShell';
|
|
46
47
|
import Header from '@easy-web/content-blocks/components/Header';
|
|
47
48
|
import Footer from '@easy-web/content-blocks/components/Footer';
|
|
48
49
|
import { siteConfig } from '../config';
|
|
50
|
+
import { i18n } from '../lib/i18n';
|
|
49
51
|
|
|
50
52
|
interface Props {
|
|
51
53
|
lang: string;
|
|
@@ -63,19 +65,25 @@ const legalLinks = siteConfig.legalLinks[lang];
|
|
|
63
65
|
<title>{title}</title>
|
|
64
66
|
</head>
|
|
65
67
|
<body>
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
<PageShell skipLabel={siteConfig.skipLabel[lang]}>
|
|
69
|
+
<Header
|
|
70
|
+
slot="header"
|
|
71
|
+
siteName={siteConfig.siteName}
|
|
72
|
+
navItems={navItems}
|
|
73
|
+
currentLang={lang}
|
|
74
|
+
pathname={pathname}
|
|
75
|
+
alternateHref={alternateHref}
|
|
76
|
+
locales={i18n.locales}
|
|
77
|
+
/>
|
|
78
|
+
<slot />
|
|
79
|
+
<Footer slot="footer" siteName={siteConfig.siteName} legalLinks={legalLinks} />
|
|
80
|
+
</PageShell>
|
|
75
81
|
</body>
|
|
76
82
|
</html>
|
|
77
83
|
```
|
|
78
84
|
|
|
85
|
+
`PageShell` supplies the skip link and the `<main>` landmark; without it this layout ships a WCAG 2.1 SC 2.4.1 failure that an axe gate does not catch. `locales` suppresses the language switch on single-locale sites. Both are explained under [Site chrome](#site-chrome).
|
|
86
|
+
|
|
79
87
|
### Page — compose Hero + Section + CardGrid + Card
|
|
80
88
|
|
|
81
89
|
```astro
|
|
@@ -116,13 +124,48 @@ All components use the `--ew-*` design tokens from `@easy-web/theme-core`. None
|
|
|
116
124
|
|
|
117
125
|
| Component | Required props | Optional props | Notes |
|
|
118
126
|
| :--- | :--- | :--- | :--- |
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
127
|
+
| `PageShell` | — | `mainId?: string`, `skipLabel?: string`, `class?: string` | Document landmark scaffold: skip link → `header` slot → `<main>` → `footer` slot. Owns that DOM order. `mainId` defaults to `main-content`, `skipLabel` to `'Skip to main content'` — **set it per locale**. |
|
|
128
|
+
| `Header` | `siteName: string`, `navItems: NavItem[]`, `currentLang: string`, `pathname: string` | `brandHref?: string`, `alternateHref?: string`, `menuLabel?: string`, `logo?: string`, `navId?: string`, `locales?: readonly string[]` | Sticky responsive header with `actions` slot. Mobile hamburger menu (scoped vanilla JS). Default slot fallback renders `ThemeToggle` + `LanguageSwitch` — the switch is omitted when `locales` holds a single entry. `navId` defaults to `ew-header-nav`. `data-testid="header-classic"`. |
|
|
129
|
+
| `HeaderCentered` | `siteName: string`, `navItems: NavItem[]`, `currentLang: string`, `pathname: string` | `alternateHref?: string`, `menuLabel?: string`, `logo?: string`, `navId?: string`, `locales?: readonly string[]` | Variant: brand centered, nav links split left/right. Same `actions` slot and mobile hamburger. `navId` defaults to `ew-header-centered-nav`. `data-testid="header-centered"`. |
|
|
130
|
+
| `HeaderHideOnScroll` | `siteName: string`, `navItems: NavItem[]`, `currentLang: string`, `pathname: string` | `alternateHref?: string`, `menuLabel?: string`, `logo?: string`, `navId?: string`, `locales?: readonly string[]` | Variant: `position: fixed` header that slides off screen on scroll-down, reappears on scroll-up. Compensates body padding via JS. `navId` defaults to `ew-header-hos-nav`. `data-testid="header-hide-on-scroll"`. |
|
|
131
|
+
| `HeaderFlyout` | `siteName: string`, `navItems: NavItem[]`, `currentLang: string`, `pathname: string` | `alternateHref?: string`, `menuLabel?: string`, `logo?: string`, `navId?: string`, `locales?: readonly string[]` | Variant: items with `children[]` show a flyout dropdown (hover/focus desktop, click mobile, keyboard accessible). `navId` defaults to `ew-header-flyout-nav` and also prefixes each dropdown's id. `data-testid="header-flyout"`. |
|
|
123
132
|
| `Footer` | `siteName: string`, `legalLinks: Array<{ label: string; href: string }>` | — | Simple copyright + legal-link footer. |
|
|
124
133
|
| `ThemeToggle` | — | — | Light / dark / system trio button. Talks to `@easy-web/theme-core` via `data-theme` on `<html>` and `localStorage`. |
|
|
125
|
-
| `LanguageSwitch` | `currentLang: string`, `pathname: string` | `alternateHref?: string` | DE ↔ EN switcher. If `alternateHref` is provided, links there directly; otherwise infers the alternate path from `pathname`. |
|
|
134
|
+
| `LanguageSwitch` | `currentLang: string`, `pathname: string` | `alternateHref?: string` | DE ↔ EN switcher. If `alternateHref` is provided, links there directly; otherwise infers the alternate path from `pathname`. Always renders when used directly — it has no concept of how many locales the site serves; the header variants gate it on their `locales` prop. |
|
|
135
|
+
|
|
136
|
+
#### `PageShell` — skip link and `<main>` landmark
|
|
137
|
+
|
|
138
|
+
A layout that renders `<Header /> <slot /> <Footer />` produces a document with no `<main>` landmark and no way to bypass the navigation. That fails WCAG 2.1 SC 2.4.1 "Bypass Blocks" (Level A) on every route whose content does not open with a heading.
|
|
139
|
+
|
|
140
|
+
It fails quietly: axe-core reports this through its `bypass` rule, which carries `reviewOnFail`, so it lands in `incomplete` rather than `violations` — an accessibility gate asserting `violations.length === 0` stays green while the failure ships.
|
|
141
|
+
|
|
142
|
+
`PageShell` owns the document order, because the skip link has to be the first focusable element and a caller that renders its own header cannot arrange that. Header and footer therefore arrive as named slots:
|
|
143
|
+
|
|
144
|
+
```astro
|
|
145
|
+
---
|
|
146
|
+
// src/layouts/Base.astro
|
|
147
|
+
import PageShell from '@easy-web/content-blocks/components/PageShell';
|
|
148
|
+
import Header from '@easy-web/content-blocks/components/Header';
|
|
149
|
+
import Footer from '@easy-web/content-blocks/components/Footer';
|
|
150
|
+
import { m } from '../paraglide/messages';
|
|
151
|
+
---
|
|
152
|
+
<body>
|
|
153
|
+
<PageShell skipLabel={m.skip_to_main()}>
|
|
154
|
+
<Header slot="header" siteName={siteConfig.siteName} navItems={navItems} currentLang={locale} pathname={pathname} locales={i18n.locales} />
|
|
155
|
+
<slot />
|
|
156
|
+
<Footer slot="footer" siteName={siteConfig.siteName} legalLinks={legalLinks} />
|
|
157
|
+
</PageShell>
|
|
158
|
+
</body>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Rendered order is skip link → `header` slot → `<main>` → `footer` slot.
|
|
162
|
+
|
|
163
|
+
`skipLabel` defaults to English (`'Skip to main content'`). **Source it from your message catalogue, not a literal** — it is visible text, and on a non-English site a hardcoded default is the one string on the page that is not translated.
|
|
164
|
+
|
|
165
|
+
Two details are load-bearing and should survive any re-implementation:
|
|
166
|
+
|
|
167
|
+
* `<main>` carries `tabindex="-1"` so activating the skip link moves focus, not just scroll position. Without it some browsers scroll the viewport but leave focus in the nav, so the next Tab returns to the menu — the control looks like it works while bypassing nothing.
|
|
168
|
+
* The skip link is positioned off-screen rather than `display: none`, because a hidden element leaves the focus order entirely and would be unreachable by exactly the keyboard users it exists for.
|
|
126
169
|
|
|
127
170
|
#### Header `actions` slot
|
|
128
171
|
|
|
@@ -150,6 +193,30 @@ import HeaderFlyout from '@easy-web/content-blocks/components/HeaderFlyout';
|
|
|
150
193
|
<HeaderFlyout siteName="My Site" navItems={navItemsWithChildren} currentLang="de" pathname={pathname} />
|
|
151
194
|
```
|
|
152
195
|
|
|
196
|
+
#### Single-locale sites — the `locales` prop
|
|
197
|
+
|
|
198
|
+
`LanguageSwitch` derives its target as "the other locale" (`de` ↔ `en`). On a site that serves one locale that target is a route the site never builds, so the header shipped a control leading to a 404.
|
|
199
|
+
|
|
200
|
+
Pass the locales the site actually serves and the switch is omitted when there is only one:
|
|
201
|
+
|
|
202
|
+
```astro
|
|
203
|
+
---
|
|
204
|
+
// src/layouts/Base.astro
|
|
205
|
+
import { i18n } from '../lib/i18n'; // createI18n({ locales: ['de'] as const, … })
|
|
206
|
+
---
|
|
207
|
+
<Header
|
|
208
|
+
siteName={siteConfig.siteName}
|
|
209
|
+
navItems={navItems}
|
|
210
|
+
currentLang={locale}
|
|
211
|
+
pathname={pathname}
|
|
212
|
+
locales={i18n.locales}
|
|
213
|
+
/>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Feed it from the instance's `createI18n()` call rather than a hand-written array or a boolean flag — that keeps one declaration of the locale set behind the header, the hreflang links and the sitemap alternates, so they cannot drift apart.
|
|
217
|
+
|
|
218
|
+
Omitting the prop keeps the switch rendering unconditionally, so existing bilingual consumers are unaffected. Suppressing the switch via the `actions` slot also works, but it replaces the whole control group — you then have to re-supply `ThemeToggle` yourself.
|
|
219
|
+
|
|
153
220
|
Selecting the header variant in a Base layout via a `headerVariant` prop:
|
|
154
221
|
|
|
155
222
|
```astro
|
|
@@ -321,9 +388,9 @@ Components use BEM-style class names prefixed with `ew-` (e.g., `.ew-hero`, `.ew
|
|
|
321
388
|
|
|
322
389
|
## Adoption status
|
|
323
390
|
|
|
324
|
-
The published version is `1.
|
|
391
|
+
The published version is `1.2.3`. Three site instances consume this package at `^1.2.3`: a pilot that validates every release first, and two customer sites.
|
|
325
392
|
|
|
326
|
-
The
|
|
393
|
+
The per-instance adoption matrix is maintained in the ecosystem's index repository, which is not public.
|
|
327
394
|
|
|
328
395
|
## See also
|
|
329
396
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-web/content-blocks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Reusable Astro content-block components for the easy-web ecosystem.",
|
|
6
6
|
"exports": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"zod": ">=4.0.0"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@easy-web/i18n": "1.
|
|
27
|
-
"@easy-web/theme-core": "1.
|
|
26
|
+
"@easy-web/i18n": "1.3.0",
|
|
27
|
+
"@easy-web/theme-core": "1.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"astro": "^6.4.0",
|
|
@@ -19,10 +19,23 @@ interface Props {
|
|
|
19
19
|
menuLabel?: string;
|
|
20
20
|
/** Optional logo URL. When provided, renders an <img> in the brand area instead of site name text. */
|
|
21
21
|
logo?: string;
|
|
22
|
+
/**
|
|
23
|
+
* DOM id linking the menu button's `aria-controls` to the `<nav>`.
|
|
24
|
+
* Stable by default so builds are reproducible. Override only when rendering
|
|
25
|
+
* more than one of this header variant on a single page.
|
|
26
|
+
*/
|
|
27
|
+
navId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Locales this site actually serves. When it holds a single entry the
|
|
30
|
+
* language switch is omitted, because on a one-locale site it is a control
|
|
31
|
+
* that navigates to a route the site does not build. Omit the prop to keep
|
|
32
|
+
* the switch rendering unconditionally.
|
|
33
|
+
*/
|
|
34
|
+
locales?: readonly string[];
|
|
22
35
|
}
|
|
23
36
|
|
|
24
|
-
const { siteName, navItems, currentLang, pathname, brandHref, alternateHref, menuLabel = 'Toggle navigation menu', logo } = Astro.props;
|
|
25
|
-
const
|
|
37
|
+
const { siteName, navItems, currentLang, pathname, brandHref, alternateHref, menuLabel = 'Toggle navigation menu', logo, navId = 'ew-header-nav', locales } = Astro.props;
|
|
38
|
+
const showLanguageSwitch = !locales || locales.length > 1;
|
|
26
39
|
---
|
|
27
40
|
|
|
28
41
|
<header class="ew-header" data-testid="header-classic">
|
|
@@ -63,7 +76,7 @@ const navId = `ew-header-nav-${Math.random().toString(36).slice(2, 9)}`;
|
|
|
63
76
|
<div class="ew-header__actions">
|
|
64
77
|
<slot name="actions">
|
|
65
78
|
<ThemeToggle />
|
|
66
|
-
<LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />
|
|
79
|
+
{showLanguageSwitch && <LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />}
|
|
67
80
|
</slot>
|
|
68
81
|
</div>
|
|
69
82
|
</nav>
|
|
@@ -11,10 +11,23 @@ interface Props {
|
|
|
11
11
|
menuLabel?: string;
|
|
12
12
|
/** Optional logo URL. When provided, renders an <img> in the brand area instead of site name text. */
|
|
13
13
|
logo?: string;
|
|
14
|
+
/**
|
|
15
|
+
* DOM id linking the menu button's `aria-controls` to the `<nav>`.
|
|
16
|
+
* Stable by default so builds are reproducible. Override only when rendering
|
|
17
|
+
* more than one of this header variant on a single page.
|
|
18
|
+
*/
|
|
19
|
+
navId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Locales this site actually serves. When it holds a single entry the
|
|
22
|
+
* language switch is omitted, because on a one-locale site it is a control
|
|
23
|
+
* that navigates to a route the site does not build. Omit the prop to keep
|
|
24
|
+
* the switch rendering unconditionally.
|
|
25
|
+
*/
|
|
26
|
+
locales?: readonly string[];
|
|
14
27
|
}
|
|
15
28
|
|
|
16
|
-
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = 'Toggle navigation menu', logo } = Astro.props;
|
|
17
|
-
const
|
|
29
|
+
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = 'Toggle navigation menu', logo, navId = 'ew-header-centered-nav', locales } = Astro.props;
|
|
30
|
+
const showLanguageSwitch = !locales || locales.length > 1;
|
|
18
31
|
const mid = Math.ceil(navItems.length / 2);
|
|
19
32
|
const leftItems = navItems.slice(0, mid);
|
|
20
33
|
const rightItems = navItems.slice(mid);
|
|
@@ -50,7 +63,7 @@ const rightItems = navItems.slice(mid);
|
|
|
50
63
|
<div class="ew-header-centered__actions">
|
|
51
64
|
<slot name="actions">
|
|
52
65
|
<ThemeToggle />
|
|
53
|
-
<LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />
|
|
66
|
+
{showLanguageSwitch && <LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />}
|
|
54
67
|
</slot>
|
|
55
68
|
</div>
|
|
56
69
|
</div>
|
|
@@ -18,10 +18,23 @@ interface Props {
|
|
|
18
18
|
menuLabel?: string;
|
|
19
19
|
/** Optional logo URL. When provided, renders an <img> in the brand area instead of site name text. */
|
|
20
20
|
logo?: string;
|
|
21
|
+
/**
|
|
22
|
+
* DOM id linking the menu button's `aria-controls` to the `<nav>`, and the
|
|
23
|
+
* prefix for each dropdown's id. Stable by default so builds are reproducible.
|
|
24
|
+
* Override only when rendering more than one of this header variant on a single page.
|
|
25
|
+
*/
|
|
26
|
+
navId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Locales this site actually serves. When it holds a single entry the
|
|
29
|
+
* language switch is omitted, because on a one-locale site it is a control
|
|
30
|
+
* that navigates to a route the site does not build. Omit the prop to keep
|
|
31
|
+
* the switch rendering unconditionally.
|
|
32
|
+
*/
|
|
33
|
+
locales?: readonly string[];
|
|
21
34
|
}
|
|
22
35
|
|
|
23
|
-
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = 'Toggle navigation menu', logo } = Astro.props;
|
|
24
|
-
const
|
|
36
|
+
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = 'Toggle navigation menu', logo, navId = 'ew-header-flyout-nav', locales } = Astro.props;
|
|
37
|
+
const showLanguageSwitch = !locales || locales.length > 1;
|
|
25
38
|
const dropdownIdPrefix = `${navId}-dropdown`;
|
|
26
39
|
---
|
|
27
40
|
|
|
@@ -104,7 +117,7 @@ const dropdownIdPrefix = `${navId}-dropdown`;
|
|
|
104
117
|
<div class="ew-header-flyout__actions">
|
|
105
118
|
<slot name="actions">
|
|
106
119
|
<ThemeToggle />
|
|
107
|
-
<LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />
|
|
120
|
+
{showLanguageSwitch && <LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />}
|
|
108
121
|
</slot>
|
|
109
122
|
</div>
|
|
110
123
|
</nav>
|
|
@@ -13,10 +13,23 @@ interface Props {
|
|
|
13
13
|
menuLabel?: string;
|
|
14
14
|
/** Optional logo URL. When provided, renders an <img> in the brand area instead of site name text. */
|
|
15
15
|
logo?: string;
|
|
16
|
+
/**
|
|
17
|
+
* DOM id linking the menu button's `aria-controls` to the `<nav>`.
|
|
18
|
+
* Stable by default so builds are reproducible. Override only when rendering
|
|
19
|
+
* more than one of this header variant on a single page.
|
|
20
|
+
*/
|
|
21
|
+
navId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Locales this site actually serves. When it holds a single entry the
|
|
24
|
+
* language switch is omitted, because on a one-locale site it is a control
|
|
25
|
+
* that navigates to a route the site does not build. Omit the prop to keep
|
|
26
|
+
* the switch rendering unconditionally.
|
|
27
|
+
*/
|
|
28
|
+
locales?: readonly string[];
|
|
16
29
|
}
|
|
17
30
|
|
|
18
|
-
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = 'Toggle navigation menu', logo } = Astro.props;
|
|
19
|
-
const
|
|
31
|
+
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = 'Toggle navigation menu', logo, navId = 'ew-header-hos-nav', locales } = Astro.props;
|
|
32
|
+
const showLanguageSwitch = !locales || locales.length > 1;
|
|
20
33
|
---
|
|
21
34
|
|
|
22
35
|
<header class="ew-header-hide-on-scroll" data-testid="header-hide-on-scroll">
|
|
@@ -57,7 +70,7 @@ const navId = `ew-header-hos-nav-${Math.random().toString(36).slice(2, 9)}`;
|
|
|
57
70
|
<div class="ew-header-hide-on-scroll__actions">
|
|
58
71
|
<slot name="actions">
|
|
59
72
|
<ThemeToggle />
|
|
60
|
-
<LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />
|
|
73
|
+
{showLanguageSwitch && <LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} />}
|
|
61
74
|
</slot>
|
|
62
75
|
</div>
|
|
63
76
|
</nav>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* PageShell – document-level landmark scaffold: skip link, <main>, and slots for
|
|
4
|
+
* the site header and footer.
|
|
5
|
+
*
|
|
6
|
+
* Exists because a layout that renders `<Header /> <slot /> <Footer />` produces
|
|
7
|
+
* a document with no `<main>` landmark and no way to bypass the navigation. That
|
|
8
|
+
* fails WCAG 2.1 success criterion 2.4.1 "Bypass Blocks" (Level A), which is
|
|
9
|
+
* satisfied by a skip link, a heading, or a landmark region — and such a layout
|
|
10
|
+
* offers none of the three on any route whose content does not open with a
|
|
11
|
+
* heading. axe-core reports this as `bypass`, and because that rule carries
|
|
12
|
+
* `reviewOnFail`, it surfaces as *incomplete* rather than a violation, so a gate
|
|
13
|
+
* asserting `violations.length === 0` stays green while the failure ships.
|
|
14
|
+
*
|
|
15
|
+
* This component owns the DOM order on purpose: the skip link has to precede the
|
|
16
|
+
* header to be the first focusable element, which a layout cannot arrange if the
|
|
17
|
+
* header is rendered by the caller before the shell.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* <PageShell>
|
|
21
|
+
* <Header slot="header" ... />
|
|
22
|
+
* <slot />
|
|
23
|
+
* <Footer slot="footer" ... />
|
|
24
|
+
* </PageShell>
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
/** id of the <main> element and the skip link's target. */
|
|
29
|
+
mainId?: string;
|
|
30
|
+
/** Skip-link text. Set this per locale; the default is English. */
|
|
31
|
+
skipLabel?: string;
|
|
32
|
+
/** Extra class(es) for the <main> element. */
|
|
33
|
+
class?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { mainId = 'main-content', skipLabel = 'Skip to main content', class: className } = Astro.props;
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
<a class="ew-skip-link" href={`#${mainId}`}>{skipLabel}</a>
|
|
40
|
+
<slot name="header" />
|
|
41
|
+
<!--
|
|
42
|
+
tabindex="-1" makes <main> programmatically focusable so activating the skip
|
|
43
|
+
link moves focus as well as scroll position. Without it, some browsers scroll
|
|
44
|
+
the viewport but leave focus in the nav, so the next Tab returns to the menu —
|
|
45
|
+
the control appears to work while not actually bypassing anything.
|
|
46
|
+
-->
|
|
47
|
+
<main id={mainId} class:list={['ew-main', className]} tabindex="-1">
|
|
48
|
+
<slot />
|
|
49
|
+
</main>
|
|
50
|
+
<slot name="footer" />
|
|
51
|
+
|
|
52
|
+
<style>
|
|
53
|
+
/*
|
|
54
|
+
Off-screen until focused rather than `display: none` — a hidden element is
|
|
55
|
+
removed from the focus order entirely, which would make the skip link
|
|
56
|
+
unreachable by the keyboard users it exists for.
|
|
57
|
+
*/
|
|
58
|
+
.ew-skip-link {
|
|
59
|
+
position: absolute;
|
|
60
|
+
left: -9999px;
|
|
61
|
+
top: 0;
|
|
62
|
+
z-index: 100;
|
|
63
|
+
padding: var(--ew-space-2) var(--ew-space-4);
|
|
64
|
+
background: var(--ew-surface);
|
|
65
|
+
color: var(--ew-on-surface);
|
|
66
|
+
border: 1px solid var(--ew-border);
|
|
67
|
+
border-radius: var(--ew-radius-md);
|
|
68
|
+
font-family: var(--ew-font-sans);
|
|
69
|
+
font-size: var(--ew-text-base);
|
|
70
|
+
font-weight: 600;
|
|
71
|
+
text-decoration: none;
|
|
72
|
+
}
|
|
73
|
+
.ew-skip-link:focus-visible,
|
|
74
|
+
.ew-skip-link:focus {
|
|
75
|
+
left: var(--ew-space-3);
|
|
76
|
+
top: var(--ew-space-3);
|
|
77
|
+
outline: 2px solid var(--ew-primary);
|
|
78
|
+
outline-offset: 2px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* The landmark itself is layout-neutral; instances style it via `class`. */
|
|
82
|
+
.ew-main:focus {
|
|
83
|
+
outline: none;
|
|
84
|
+
}
|
|
85
|
+
</style>
|