Skip to content

feat: require alt attribute for accessibility#2144

Open
DamianGlowala wants to merge 9 commits intomainfrom
feat/required-alt-attribute
Open

feat: require alt attribute for accessibility#2144
DamianGlowala wants to merge 9 commits intomainfrom
feat/required-alt-attribute

Conversation

@DamianGlowala
Copy link
Member

@DamianGlowala DamianGlowala commented Feb 26, 2026

🔗 Linked issue

related to #1612
resolves #315

📚 Description

This PR enforces either an explicit empty alt="", or alt="..." with a meaningful value for better accessibility.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 26, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/image@2144

commit: 7efbe67

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 26, 2026

Deploying nuxt-image with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7efbe67
Status: ✅  Deploy successful!
Preview URL: https://7efe09f8.nuxt-image.pages.dev
Branch Preview URL: https://feat-required-alt-attribute.nuxt-image.pages.dev

View logs

@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

This pull request enforces the use of alt attributes on image components by making alt a required property in the BaseImageProps interface. The change is propagated throughout the codebase by adding alt attributes (set to empty strings where not previously specified) to all image component instances in examples, playground pages, and test files. The Provider interface in providers.ts is updated to require an alt field for sample objects. Two e2e tests are modified to use the locator() API instead of getByRole() for image element selection, and snapshot expectations across multiple test files are updated to reflect the addition of alt attributes in the rendered HTML output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes to test/e2e files replace getByRole('img') with locator('img'), which appears unrelated to enforcing alt attributes and falls outside the stated accessibility objective. Remove or justify the test query changes in test/e2e/no-ssr.test.ts and test/e2e/ssr.test.ts as they are unrelated to alt attribute enforcement.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: require alt attribute for accessibility' clearly and concisely describes the main change of making alt attributes mandatory for accessibility compliance.
Linked Issues check ✅ Passed The PR makes alt a required prop in the BaseImageProps interface [src/runtime/utils/props.ts] and propagates it throughout the codebase, addressing the core requirement from issue #315 to enforce alt attribute usage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly relates to the changeset by explaining the purpose: enforcing alt attributes on image components for accessibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/required-alt-attribute

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/runtime/utils/props.ts`:
- Line 50: The object literal assigned to normalizedAttrs is missing a trailing
comma after the property alt: props.alt which is causing the lint failure;
update the normalizedAttrs object (the entry with alt: props.alt) to include a
trailing comma after that property so the object conforms to the project's
trailing-comma lint rule.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 510f2e1 and 3746ba6.

📒 Files selected for processing (1)
  • src/runtime/utils/props.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/nuxt/picture.test.ts (1)

59-59: Stale TODO: Consider removing or implementing this test.

This it.todo('alt attribute is generated') appears outdated now that alt is a required prop and is verified to appear in multiple snapshot tests above and below. You could either:

  1. Remove this TODO since alt propagation is already tested via snapshots
  2. Convert it to an explicit test if specific alt behavior needs validation
🧹 Option to remove the stale TODO
-  it.todo('alt attribute is generated')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/nuxt/picture.test.ts` at line 59, Remove the stale test placeholder
it.todo('alt attribute is generated') in test/nuxt/picture.test.ts because alt
is already required and covered by existing snapshots; if you instead want an
explicit behavioral test, replace that TODO with a concrete it('generates alt
attribute', ...) that mounts the Picture component and asserts the rendered
element includes the expected alt text (reference the it.todo string to find the
location and the Picture component tests above/below for mounting/snapping
patterns).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@example/app.vue`:
- Line 11: Replace the empty alt attributes on the content images inside the
<figure> elements with meaningful descriptive text that conveys the photo
content (e.g., describe the mountain scene) so they are not treated as
decorative; update the alt="" values for the <img> elements referenced alongside
their <figcaption> elements (both occurrences) to brief descriptive phrases that
match the captions and the image purpose.

---

Nitpick comments:
In `@test/nuxt/picture.test.ts`:
- Line 59: Remove the stale test placeholder it.todo('alt attribute is
generated') in test/nuxt/picture.test.ts because alt is already required and
covered by existing snapshots; if you instead want an explicit behavioral test,
replace that TODO with a concrete it('generates alt attribute', ...) that mounts
the Picture component and asserts the rendered element includes the expected alt
text (reference the it.todo string to find the location and the Picture
component tests above/below for mounting/snapping patterns).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3746ba6 and 3cdb13c.

📒 Files selected for processing (4)
  • example/app.vue
  • src/runtime/utils/props.ts
  • test/nuxt/image.test.ts
  • test/nuxt/picture.test.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/unit/bundle.test.ts (1)

30-30: ⚠️ Potential issue | 🟡 Minor

Missing required alt attributes in test template.

Since this PR makes alt a required prop, the test template should include alt attributes to be consistent with other updated tests and avoid potential console warnings.

Proposed fix
-  await writeFile(join(rootDir, 'app.vue'), `<template><NuxtImg src="/test.jpg" /><NuxtPicture src="/test.jpg" /></template>`)
+  await writeFile(join(rootDir, 'app.vue'), `<template><NuxtImg src="/test.jpg" alt="" /><NuxtPicture src="/test.jpg" alt="" /></template>`)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/unit/bundle.test.ts` at line 30, The test template written by the
writeFile call that creates app.vue is missing required alt props for the
components; update the string passed to writeFile(join(rootDir, 'app.vue'), ...)
so that both <NuxtImg ...> and <NuxtPicture ...> include an alt="..." attribute
(e.g., alt="test image") to match the new required prop and prevent warnings
during tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@test/unit/bundle.test.ts`:
- Line 30: The test template written by the writeFile call that creates app.vue
is missing required alt props for the components; update the string passed to
writeFile(join(rootDir, 'app.vue'), ...) so that both <NuxtImg ...> and
<NuxtPicture ...> include an alt="..." attribute (e.g., alt="test image") to
match the new required prop and prevent warnings during tests.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cdb13c and 56b8ab4.

📒 Files selected for processing (1)
  • test/unit/bundle.test.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
playground/app/pages/provider/[provider].vue (1)

13-15: Prefer preserving sample-provided alt text instead of always forcing empty alt.

On Line 15, alt="" overrides any alt from sample (Line 13), so all rendered examples become decorative even when a meaningful label exists.

Suggested change
           <nuxt-img
             :provider="provider.name as any"
             v-bind="sample"
             :preload="{ fetchPriority: 'auto' }"
-            alt=""
+            :alt="sample.alt ?? ''"
           />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@playground/app/pages/provider/`[provider].vue around lines 13 - 15, The
static alt="" is overriding any alt text provided via v-bind="sample"; update
the element so it preserves the sample-provided alt (or falls back to an empty
string) instead of always forcing an empty value—either remove the hardcoded alt
attribute or bind it to the sample value (e.g., use the sample.alt fallback) so
the component uses sample's alt when present; locate the element with
v-bind="sample" and change the alt handling accordingly.
playground/app/pages/events.vue (1)

8-8: Consider using meaningful alt text in at least some event demos.

These are valid (alt=""), but using non-empty alt on content images would better demonstrate accessible defaults for users copying playground patterns.

Also applies to: 15-15, 25-25, 33-33, 42-42, 49-49

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@playground/app/pages/events.vue` at line 8, Several demo images in events.vue
currently use empty alt attributes (alt="") which is valid but not illustrative;
update some of the <img> elements to include meaningful, concise alt text that
describes the image content (e.g., "Concert poster for Jazz Night", "Event
location map", "Speaker headshot") so the playground demonstrates accessible
defaults—locate the img tags around the instances noted (lines with alt="" in
events.vue) and replace the empty alt values with appropriate descriptive
strings for each demo image.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@playground/app/pages/events.vue`:
- Line 8: Several demo images in events.vue currently use empty alt attributes
(alt="") which is valid but not illustrative; update some of the <img> elements
to include meaningful, concise alt text that describes the image content (e.g.,
"Concert poster for Jazz Night", "Event location map", "Speaker headshot") so
the playground demonstrates accessible defaults—locate the img tags around the
instances noted (lines with alt="" in events.vue) and replace the empty alt
values with appropriate descriptive strings for each demo image.

In `@playground/app/pages/provider/`[provider].vue:
- Around line 13-15: The static alt="" is overriding any alt text provided via
v-bind="sample"; update the element so it preserves the sample-provided alt (or
falls back to an empty string) instead of always forcing an empty value—either
remove the hardcoded alt attribute or bind it to the sample value (e.g., use the
sample.alt fallback) so the component uses sample's alt when present; locate the
element with v-bind="sample" and change the alt handling accordingly.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e359a70 and 7ace4b4.

📒 Files selected for processing (6)
  • playground/app/pages/events.vue
  • playground/app/pages/img.vue
  • playground/app/pages/ipx-layers.vue
  • playground/app/pages/picture.vue
  • playground/app/pages/provider/[provider].vue
  • playground/app/pages/responsive.vue
✅ Files skipped from review due to trivial changes (1)
  • playground/app/pages/ipx-layers.vue

@DamianGlowala DamianGlowala changed the title feat: require alt attribute for accessibility feat: require alt attribute for accessibility Feb 27, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
playground/app/providers.ts (1)

27-27: Consider adding descriptive alt text for consistency.

Most samples use alt: '' while some providers (strapi, storyblok, wagtail, directus) include meaningful descriptions. For a playground demonstrating image provider capabilities, descriptive alt text like "Bunny CDN sharpened image" or "Cloudinary cropped thumbnail" would improve documentation value and serve as better examples for users learning the module.

Empty alt is valid per WCAG for decorative images, so this is entirely optional.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@playground/app/providers.ts` at line 27, Replace the empty alt value (alt:
'') in the provider object with a descriptive string to improve example
documentation; locate the provider entry that contains the alt property (e.g.,
the provider object in providers.ts) and set alt to a meaningful description
such as "Bunny CDN sharpened image" or "Cloudinary cropped thumbnail" depending
on the provider, preserving empty string only if the image is purely decorative.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@playground/app/providers.ts`:
- Line 27: Replace the empty alt value (alt: '') in the provider object with a
descriptive string to improve example documentation; locate the provider entry
that contains the alt property (e.g., the provider object in providers.ts) and
set alt to a meaningful description such as "Bunny CDN sharpened image" or
"Cloudinary cropped thumbnail" depending on the provider, preserving empty
string only if the image is purely decorative.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ace4b4 and 7efbe67.

📒 Files selected for processing (3)
  • playground/app/providers.ts
  • test/e2e/no-ssr.test.ts
  • test/e2e/ssr.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce usage of alt text

2 participants