Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<NuxtRouteAnnouncer />
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
Expand Down
3 changes: 1 addition & 2 deletions layers/home/components/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,11 @@ const componentFor = (slide: NormalizedSlide) => {
<div class="relative">

<!-- Ratio wrapper -->
<!-- focusable swipe surface; pointer/touch gestures have keyboard parity via the section keydown handler -->
<!-- swipe surface; pointer/touch gestures have keyboard parity via the section keydown handler -->
<!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions -->
<div
:class="frameClass"
:style="{ paddingTop: aspectPercent }"
tabindex="0"
@mouseenter="isHovering = true"
@mouseleave="isHovering = false"
@focusin="isHovering = true"
Expand Down
48 changes: 48 additions & 0 deletions tests/a11y/carousel-semantics.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
import { repoRoot } from '../helpers/sources'

/**
* WAI-ARIA APG carousel: a named region with aria-roledescription "carousel",
* slides as groups with roledescription "slide" and an "n of m" name. The slide
* frame used to carry tabindex="0" with no role or name; the arrow keys are
* handled on the section and reach it from every button, so the stop was
* redundant and announced nothing.
*/
const source = readFileSync(`${repoRoot}/layers/home/components/Carousel.vue`, 'utf8')
const template = source.slice(source.indexOf('<template>'))
const section = /<section\b[^>]*>/.exec(template)?.[0] ?? ''

function messages(locale: string) {
return JSON.parse(readFileSync(`${repoRoot}/i18n/locales/${locale}.json`, 'utf8')).carousel
}

describe('carousel semantics', () => {
it('is a region (a named section) with the carousel role description', () => {
// An explicit role="region" is flagged as redundant by the a11y lint.
expect(section.startsWith('<section')).toBe(true)
expect(section).toContain(':aria-label=')
expect(section).toContain('aria-roledescription="carousel"')
})

it('takes its name from i18n', () => {
expect(section).toContain(':aria-label="resolvedAriaLabel"')
expect(source).toContain("t('carousel.label')")
})

it('renders each slide as a group named "n of m"', () => {
const slide = /<div\b[^>]*role="group"[^>]*>/.exec(template)?.[0] ?? ''
expect(slide).toContain('aria-roledescription="slide"')
expect(slide).toContain(':aria-label="getSlideAriaText(s, i, slidesCount, t)"')
})

it('has no unnamed tab stop', () => {
expect(template).not.toMatch(/tabindex="0"/)
})

it.each(['en', 'de'])('has the label strings in %s', (locale) => {
const c = messages(locale)
expect(c.label, 'carousel.label').toBeTruthy()
expect(c.slide_position, 'carousel.slide_position').toMatch(/\{index\}.*\{total\}/)
})
})
29 changes: 29 additions & 0 deletions tests/a11y/route-announcer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
import { repoRoot } from '../helpers/sources'

/**
* A client-side navigation changes the title but a screen reader says nothing.
* NuxtRouteAnnouncer reads document.title (built from useHead's title
* template) into a visually hidden live region after each navigation.
*/
const template = readFileSync(`${repoRoot}/app.vue`, 'utf8').split('</template>')[0] ?? ''

describe('route announcer', () => {
it('is mounted in the app shell', () => {
expect(template, 'app.vue must render <NuxtRouteAnnouncer />').toMatch(/<NuxtRouteAnnouncer\s*\/>/)
})

it('sits outside the layout, so every layout gets it', () => {
const announcer = template.indexOf('<NuxtRouteAnnouncer')
const layoutStart = template.indexOf('<NuxtLayout')
const layoutEnd = template.indexOf('</NuxtLayout>')
expect(announcer).toBeGreaterThan(-1)
expect(announcer < layoutStart || announcer > layoutEnd, 'announcer must not be inside NuxtLayout').toBe(true)
})

it('announces the page title, which the title template supplies', () => {
const source = readFileSync(`${repoRoot}/app.vue`, 'utf8')
expect(source).toContain('titleTemplate')
})
})
Loading