ui icon indicating copy to clipboard operation
ui copied to clipboard

[bug]: Dialog and Sheet have no background

Open rytelk opened this issue 1 year ago • 6 comments

Describe the bug

Dialog and Sheet has no background

Affected component/components

Sheet, Dialog

How to reproduce

  1. Create new project npx shadcn@latest init dialog
  2. Replace `page.tsx' with the following code
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"

export default function Home() {
  return (
    <Dialog>
      <DialogTrigger asChild>
        <div>Open</div>
      </DialogTrigger>
      <DialogContent className="sm:max-w-md">
        <DialogHeader>
          <DialogTitle>Test title</DialogTitle>
          <DialogDescription>
            Test description
          </DialogDescription>
        </DialogHeader>
        <div>Test content</div>
      </DialogContent>
    </Dialog>
  )
}
  1. Run application and open the dialog
  2. See the following result: image

Temporary fix:

I modified the background class in the dialog component from bg-background to bg-[var(--background)], and this corrected the issue. It seems like the default background variable is not being applied correctly in some cases.

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Chrome, Windows

Before submitting

  • [X] I've made research efforts and searched the documentation
  • [X] I've searched for existing issues

rytelk avatar Sep 07 '24 16:09 rytelk

https://github.com/user-attachments/assets/ac50d10e-9b11-4479-a1ac-85320b234fcf

tldr: css variables do not seem to be working with the new cli

When I init a new shadcn project with dashboard-02 i get sheet's without a backgound. Looks like css variables are not being recognized. When I do the same thing but init and choose to NOT use css variables there is no issue

alexander-densley avatar Sep 08 '24 01:09 alexander-densley

It's just because the format of the color definition is wrong. and just delete this code in global.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

/* delete start */
:root {
  --background: #ffffff;
  --foreground: #171717;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --foreground: #ededed;
  }
}
/* delete end */

body {
  color: var(--foreground);
  background: var(--background);
  font-family: Arial, Helvetica, sans-serif;
}

@layer utilities {
  .text-balance {
    text-wrap: balance;
  }
}

@layer base {
  :root {
    --background: 0 0% 100%;
    --foreground: 0 0% 3.9%;
...

...

Because in tailwind.config.ts, bg-background is defined like this:

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        background: 'hsl(var(--background))', <- rgb(var(--background))
        foreground: 'hsl(var(--foreground))', <- rgb(var(--foreground))
      },
    },
  },
}

rgb is correct, but hsl is wrong. Do you see the difference?

aladdin-im avatar Sep 08 '24 17:09 aladdin-im

@aigc-in-all thanks! that worked!

alexander-densley avatar Sep 08 '24 19:09 alexander-densley

The issue is caused by the Tailwind setup created by create-next-app. I tried the solution above, but it didn’t work.

Solution:
Delete the tailwind.config.ts and global.css files generated by create-next-app.

Recreate these files and copy the configuration from the official Tailwind website to set up Tailwind in Next.js.

Screenshot 2024-09-10 at 5 45 44 PM

Screenshot 2024-09-10 at 5 45 54 PM

Then, run npx shadcn@latest init.

This will fix the issue.

veerbal1 avatar Sep 10 '24 12:09 veerbal1

The issue is caused by the Tailwind setup created by create-next-app. I tried the solution above, but it didn’t work.

Solution: Delete the tailwind.config.ts and global.css files generated by create-next-app.

Recreate these files and copy the configuration from the official Tailwind website to set up Tailwind in Next.js.

Screenshot 2024-09-10 at 5 45 44 PM

Screenshot 2024-09-10 at 5 45 54 PM

Then, run npx shadcn@latest init.

This will fix the issue.

This worked for me - Note: you also have to delete the components.json if it exists before you can run the fresh init.

leon-lonsdale avatar Sep 10 '24 14:09 leon-lonsdale

for me, if I am setting colors using the hex string (#000000) then the sheet will have no background. but if I update it to use the correct hsl numbers (0 0 0) then it works

this does not work:

@layer base {
  :root {
    --background: 0 0% 100%;
   }
   .dark{
   --background: #414141;
   }
}

this does work

@layer base {
  :root {
    --background: 0 0% 100%;
   }
   .dark{
    --background: 0 0 8;
   }
}

nickfrosty avatar Sep 13 '24 01:09 nickfrosty

This issue has been automatically marked as stale due to one year of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you. (This is an automated message)

shadcn avatar Sep 13 '25 23:09 shadcn