Skip to content

Commit 1fce26e

Browse files
committed
Improve touch target area on Markdown header anchors to meet WCAG requirements
1 parent 143a352 commit 1fce26e

6 files changed

Lines changed: 26 additions & 20 deletions

File tree

‎src/components/Home/Hero/__tests__/index.spec.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ describe('Home Hero (Astro)', () => {
4747

4848
const readyClass = readyLink?.getAttribute('class') || ''
4949
expect(readyClass).toContain('no-underline')
50+
expect(readyClass).toContain('min-h-6')
51+
expect(readyClass).toContain('min-w-6')
5052
expect(readyClass).toContain('text-success')
5153
expect(readyClass).toContain('hover:text-success-offset')
5254
expect(readyClass).toContain('focus-visible:text-success-offset')

‎src/components/Home/Hero/index.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const readyLinkLabel = 'Contact me about your infrastructure needs'
4747
<span class="text-success">$</span>
4848
<a
4949
href="/contact"
50-
class="inline-flex items-center gap-1 no-underline text-success transition-colors hover:text-success-offset focus-visible:text-success-offset"
50+
class="inline-flex min-h-6 min-w-6 items-center justify-center gap-1 no-underline text-success transition-colors hover:text-success-offset focus-visible:text-success-offset"
5151
data-hero-ready-link
5252
aria-label={readyLinkLabel}
5353
>

‎src/components/Layout/Markdown/Lead/index.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const modifiedDateText = shouldShowModifiedDate && modifiedDate ? formatShortDat
3535
{author && (
3636
<a
3737
href="/about"
38-
class="font-medium no-underline hover:text-secondary focus:text-secondary"
38+
class="inline-flex min-h-6 items-center align-middle font-medium no-underline hover:text-secondary focus:text-secondary"
3939
>
4040
{author}
4141
</a>

‎src/components/Toc/client/__tests__/index.spec.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ describe('TableOfContents component rendering', () => {
118118
const overlay = root.querySelector('[data-toc-overlay]') as HTMLButtonElement | null
119119
const panel = root.querySelector('[data-toc-panel]') as HTMLElement | null
120120
const links = root.querySelectorAll('nav a')
121+
const firstLink = root.querySelector('[data-toc-link]') as HTMLAnchorElement | null
121122

122123
expect(toggleButton).toBeTruthy()
123124
expect(overlay).toBeTruthy()
124125
expect(panel).toBeTruthy()
125126
expect(links).toHaveLength(defaultHeadings.length)
127+
expect(firstLink?.className).toContain('min-h-6')
126128
expect(panel?.getAttribute('data-state')).toBe('closed')
127129
expect(root.hasAttribute('data-open')).toBe(false)
128130
expect(toggleButton?.getAttribute('aria-pressed')).toBeNull()

‎src/components/Toc/index.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const tocTree = buildTocTree(items)
9595
href={`#${node.slug}`}
9696
data-toc-link
9797
data-toc-slug={node.slug}
98-
class="block mb-2 text-sm sm:text-base text-content transition-colors hover:text-content-active data-[current=true]:text-content no-underline hover:underline"
98+
class="flex min-h-6 items-center mb-2 text-sm sm:text-base text-content transition-colors hover:text-content-active data-[current=true]:text-content no-underline hover:underline"
9999
>
100100
{node.text}
101101
</a>

‎test/e2e/specs/11-accessibility/wcag-compliance.spec.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('WCAG Compliance', () => {
1414
* exception applies. This test intentionally checks only the simple minimum-size case and
1515
* does not attempt to model the spacing exception.
1616
*/
17-
test.only('@wip touch targets are at least 24x24 pixels', async ({ page: playwrightPage }) => {
17+
test.only('@ready touch targets are at least 24x24 pixels', async ({ page: playwrightPage }) => {
1818
const page = await BasePage.init(playwrightPage)
1919

2020
for (const url of pages) {
@@ -75,23 +75,25 @@ describe('WCAG Compliance', () => {
7575
*/
7676
test('@ready text has sufficient color contrast', async ({ page: playwrightPage }) => {
7777
const page = await BasePage.init(playwrightPage)
78-
await page.goto('/')
79-
80-
// Sample a few text elements
81-
const paragraphs = page.locator('p').first()
82-
const hasVisibleText = await paragraphs.isVisible()
83-
84-
if (hasVisibleText) {
85-
const contrast = await paragraphs.evaluate((el) => {
86-
const styles = window.getComputedStyle(el)
87-
return {
88-
color: styles.color,
89-
backgroundColor: styles.backgroundColor,
90-
}
91-
})
78+
for (const url of pages) {
79+
await page.goto(url)
80+
81+
// Sample a few text elements
82+
const paragraphs = page.locator('p').first()
83+
const hasVisibleText = await paragraphs.isVisible()
84+
85+
if (hasVisibleText) {
86+
const contrast = await paragraphs.evaluate((el) => {
87+
const styles = window.getComputedStyle(el)
88+
return {
89+
color: styles.color,
90+
backgroundColor: styles.backgroundColor,
91+
}
92+
})
9293

93-
// Basic check that colors are defined
94-
expect(contrast.color).toBeTruthy()
94+
// Basic check that colors are defined
95+
expect(contrast.color).toBeTruthy()
96+
}
9597
}
9698
})
9799

0 commit comments

Comments
 (0)