Skip to content

fix: correct Alert vertical alignment when title is missing #7491

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

harshith-eth
Copy link

Description

Fixes issue where Alert components with icon + description but no title were vertically offset.

Problem

When using an Alert component with an icon and description but no title:

<Alert>
    <AlertCircle className="h-4 w-4" />
    <AlertDescription>Your session has expired. Please log in again.</AlertDescription>
</Alert>

The description content was vertically offset due to the CSS selector [&>svg+div]:translate-y-[-3px] applying to the AlertDescription div when no AlertTitle was present.

Solution

Changed the CSS selector from [&>svg+div]:translate-y-[-3px] to [&>svg+h5+div]:translate-y-[-3px] to only apply the vertical offset when there's actually a title (h5 element) between the icon and description.

Changes

  • Updated apps/www/registry/default/ui/alert.tsx
  • Updated apps/www/registry/new-york/ui/alert.tsx
  • Both variants now use the more specific selector [&>svg+h5+div]:translate-y-[-3px]

Testing

This fix ensures that:

  • Alert with icon + title + description: ✅ Properly aligned (title offset by -3px)
  • Alert with icon + description only: ✅ Properly aligned (no unwanted offset)
  • Alert with title + description only: ✅ Unchanged behavior
  • Alert with description only: ✅ Unchanged behavior

Fixes #7473

Fixes shadcn-ui#7465 - corrected import path from "@/components/ui/charts" to "@/components/ui/chart" in the documentation example
Fixes issue where Alert components with icon + description but no title
were vertically offset due to CSS selector [&>svg+div]:translate-y-[-3px]
applying to AlertDescription when no AlertTitle is present.

Changed selector to [&>svg+h5+div]:translate-y-[-3px] to only apply
the offset when there's actually a title (h5) between the icon and description.

Fixes shadcn-ui#7473
Apply same fix to new-york variant - change [&>svg+div]:translate-y-[-3px]
to [&>svg+h5+div]:translate-y-[-3px] to only apply offset when title is present.

Fixes shadcn-ui#7473
Copy link

vercel bot commented May 28, 2025

@harshith-eth is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@jonathanmarchuot
Copy link

jonathanmarchuot commented May 29, 2025

Hey @harshith-eth! That's a great fix!! It definitely fixes the vertical alignment of the text, which was our primary ask!

CleanShot 2025-05-29 at 08 54 44@2x
CleanShot 2025-05-29 at 08 54 13@2x

If you're in this corner of the code, and familiar with how it works, is there any way we can also further vertically center the shape?

CleanShot 2025-05-29 at 08 55 14@2x

CleanShot 2025-05-29 at 09 45 32@2x

For context, I'm testing with Safari 18.5 and Chrome 136

Thank you for your quick response! 💛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: Alert components that include a shape and exclude a Title aren't vertically centered
2 participants