shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
74.64k stars 4.64k forks source link

[bug]: Sidebar on mobile requires a DialogTitle #5746

Open acomanescu opened 1 week ago

acomanescu commented 1 week ago

Describe the bug

When I open the sidebar on mobile I get this error:

hook.js:608 `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.

Affected component/components

Sidebar

How to reproduce

Add a sidebar, implement a trigger, emulate a mobile device and open the sidebar. The console log should display this error.

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

MacOS, Chrome

Before submitting

erikwibowo commented 1 week ago

This is work for me just change the sidebar.tsx component


if (isMobile) {
      return (
          <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
              <SheetTitle className="hidden">
              </SheetTitle> //add this
              <SheetContent
                  data-sidebar="sidebar"
                  data-mobile="true"
                  aria-describedby="" //and this
                  className="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
                  style={
                      {
                          "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
                      } as React.CSSProperties
                  }
                  side={side}
              >
                  <div className="flex h-full w-full flex-col">{children}</div>
              </SheetContent>
          </Sheet>
      );
    }
amaryassa commented 6 hours ago

In addition to @erikwibowo's suggestion, we could also add <SheetDescription className="hidden"></SheetDescription> to suppress the warning

"Warning: Missing Description or aria-describedby={undefined} for {DialogContent}. Error Component Stack.."

   if (isMobile) {
      return (
        <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
          <SheetTitle className="hidden"></SheetTitle> {/*👈🏻 */}
          <SheetDescription className="hidden"></SheetDescription> {/*👈🏻 */}

          <SheetContent
            data-sidebar="sidebar"
            data-mobile="true"
            className="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
            style={
              {
                "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
              } as React.CSSProperties
            }
            side={side}
          >
            <div className="flex h-full w-full flex-col">{children}</div>
          </SheetContent>
        </Sheet>
      );