Skip to content

Resolving Shadcn SheetContent Accessibility Error

Problem

When using Shadcn's Sheet component, you may encounter this warning in your JavaScript console:

DialogContent requires a DialogTitle for the component to be accessible for screen reader users

This occurs even though you're using a Sheet, not a Dialog. The Shadcn Sheet component is built on top of the Dialog component, inheriting its accessibility requirements. The issue happens when:

  1. Your SheetContent is missing a SheetTitle component
  2. Without a title, screen reader users won't know what the sheet represents
  3. The Shadcn components enforce accessibility rules at runtime

Here's a typical issue scenario:

jsx
<SheetContent side="right" className="fixed z-50">
  <div>
    <p>Sheet Content</p>
  </div>
</SheetContent>

Solutions

The proper solution is to add a SheetTitle component and hide it visually using CSS while keeping it accessible to screen readers:

jsx
<SheetContent side="right">
  <SheetTitle className="sr-only">
    menu
  </SheetTitle>
  <div>
    <p>Sheet Content</p>
  </div>
</SheetContent>

Why sr-only?

  • Only hides content visually
  • Remains accessible to assistive technologies
  • Maintains proper document structure

Add Visible Title

If you want the title to be visible:

jsx
<SheetContent side="right">
  <SheetTitle>Navigation Menu</SheetTitle>
  <div>
    <p>Sheet Content</p>
  </div>
</SheetContent>

Implementation Notes

sr-only vs hidden

PropertyVisualAccessibilityDOM Layout
sr-onlyHiddenAvailableUnaffected
hiddenHiddenRemovedCollapsed

Avoid hidden for accessibility

Using display: none or hidden breaks accessibility:

jsx
// ❌ Not recommended - inaccessible to screen readers
<SheetTitle className="hidden">
  Menu
</SheetTitle>

Adding sr-only Styles

If you're using Tailwind CSS, the sr-only class is built-in. For plain CSS:

css
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

Best Practices

  1. Always include a title - It's required for accessibility compliance
  2. Provide meaningful text - "Navigation Menu" is better than "Menu"
  3. Update all Sheet instances - Apply this fix anywhere you use SheetContent
  4. Test with screen readers - Verify your solution with tools like VoiceOver or NVDA

Why This Works

Shadcn's Sheet components share the same accessibility requirements as their Dialog components. By adding a semantically correct SheetTitle:

  1. Screen readers understand the sheet's purpose
  2. Accessibility warnings disappear
  3. Visual design remains unchanged (when using sr-only)
  4. Your application remains WCAG compliant

This solution resolves the console error while ensuring your app remains accessible to all users.