Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: Sheet error for screen reader users #4302

Open
2 tasks done
stefandevo opened this issue Jul 16, 2024 · 4 comments
Open
2 tasks done

[bug]: Sheet error for screen reader users #4302

stefandevo opened this issue Jul 16, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@stefandevo
Copy link

Describe the bug

When using the Sheet component I get two errors:

DialogContent requires a DialogTitle for the component to be accessible for screen reader users.
If you want to hide the DialogTitle, you can wrap it with our VisuallyHidden component.

Warning: Missing Description or aria-describedby={undefined} for {DialogContent}.

Affected component/components

Sheet

How to reproduce

Using the https://ui.shadcn.com/blocks#dashboard-05 sample. Reduce width so that the Sheet shows; warnings in the console.

Codesandbox/StackBlitz link

No response

Logs

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

If you want to hide the `DialogTitle`, you can wrap it with our VisuallyHidden component.

For more information, see https://radix-ui.com/primitives/docs/components/dialog 

---

Warning: Missing `Description` or `aria-describedby={undefined}` for {DialogContent}. 
    at DescriptionWarning (webpack-internal:///(app-pages-browser)/./node_modules/@radix-ui/react-dialog/dist/index.mjs:457:11)

System Info

All browsers.

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@stefandevo stefandevo added the bug Something isn't working label Jul 16, 2024
@stefandevo
Copy link
Author

Proposed fix in Sheet component:

const SheetContent = React.forwardRef<
  React.ElementRef<typeof SheetPrimitive.Content>,
  SheetContentProps
>(({ side = "right", className, children, ...props }, ref) => (
  <SheetPortal>
    <SheetOverlay />
    <SheetPrimitive.Content
      ref={ref}
      className={cn(sheetVariants({ side }), className)}
      {...props}
    >
      <VisuallyHidden>
        <SheetTitle>Sheet Content</SheetTitle>
        <SheetDescription>
          This is a hidden description for screen readers.
        </SheetDescription>
      </VisuallyHidden>
      {children}
      <SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
        <X className="h-4 w-4" />
        <span className="sr-only">Close</span>
      </SheetPrimitive.Close>
    </SheetPrimitive.Content>
  </SheetPortal>
));
SheetContent.displayName = SheetPrimitive.Content.displayName;

@Maqed
Copy link

Maqed commented Jul 27, 2024

First thing first you should install visually hidden component from RadixUI as Shadcn is built on top of it.

npm install @radix-ui/react-visually-hidden

Then use it as following:

          <Sheet>
            <SheetTrigger asChild>
              {/* Trigger Logic */}
            </SheetTrigger>
            <SheetContent>
              <SheetHeader>
                <VisuallyHidden>
                  <SheetTitle>Nav Content</SheetTitle>
                </VisuallyHidden>
                <SheetDescription className="flex items-center flex-col justify-between h-[300px]">
                 {/* Descrciption Logic */}
                </SheetDescription>
              </SheetHeader>
            </SheetContent>
          </Sheet>

I hope that helps!

@leandronn
Copy link

leandronn commented Aug 10, 2024

This happens with CommandDialog component as well, but there's no CommandDialogTitle to fix this.
It also happens in the shadcn site in the Command Dialog example (https://ui.shadcn.com/docs/components/command):

Screenshot 2024-08-10 at 18 43 47
Screenshot 2024-08-10 at 18 43 56

@soni-canra-wiguna
Copy link

I get the same error but in the component drawer. the solution is to add the className sr-only.

<DrawerHeader>
     <DrawerTitle className="sr-only">title</DrawerTitle>
         <DrawerDescription className="sr-only">description</DrawerDescription>
</DrawerHeader>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants