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:
- Your
SheetContent
is missing aSheetTitle
component - Without a title, screen reader users won't know what the sheet represents
- The Shadcn components enforce accessibility rules at runtime
Here's a typical issue scenario:
<SheetContent side="right" className="fixed z-50">
<div>
<p>Sheet Content</p>
</div>
</SheetContent>
Solutions
Add Title with Visual Hiding (Recommended)
The proper solution is to add a SheetTitle
component and hide it visually using CSS while keeping it accessible to screen readers:
<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:
<SheetContent side="right">
<SheetTitle>Navigation Menu</SheetTitle>
<div>
<p>Sheet Content</p>
</div>
</SheetContent>
Implementation Notes
sr-only
vs hidden
Property | Visual | Accessibility | DOM Layout |
---|---|---|---|
sr-only | Hidden | Available | Unaffected |
hidden | Hidden | Removed | Collapsed |
Avoid hidden
for accessibility
Using display: none
or hidden
breaks accessibility:
// ❌ 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:
.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
- Always include a title - It's required for accessibility compliance
- Provide meaningful text - "Navigation Menu" is better than "Menu"
- Update all Sheet instances - Apply this fix anywhere you use SheetContent
- 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
:
- Screen readers understand the sheet's purpose
- Accessibility warnings disappear
- Visual design remains unchanged (when using
sr-only
) - Your application remains WCAG compliant
This solution resolves the console error while ensuring your app remains accessible to all users.