Skip to content

Commit

Permalink
fix(EnterpriseAlert): render span when inline (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce Kalow committed Feb 15, 2023
1 parent 540598e commit 406fa0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-bikes-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/react-enterprise-alert': patch
---

Fix EnterpriseAlert so that it does not potentially generate invalid markup when used inline
8 changes: 6 additions & 2 deletions packages/enterprise-alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ function EnterpriseAlert({
className,
}: EnterpriseAlertProps) {
const { name, slug, themeClass } = useProductMeta(product)

// This ensures we aren't producing invalid HTML when rendering inline alerts within MDX. When used inline, we might end up nesting a div inside of a p. This is invalid as p cannot contain block-level elements (ref: https://www.w3.org/TR/html401/struct/text.html#h-9.3.1).
const Element = inline ? 'span' : 'div'

return (
<div
<Element
className={classNames(s.root, themeClass, className, {
[s.themed]: themeClass,
[s.inline]: inline,
Expand All @@ -50,7 +54,7 @@ function EnterpriseAlert({
)}
</p>
)}
</div>
</Element>
)
}

Expand Down

1 comment on commit 406fa0c

@vercel
Copy link

@vercel vercel bot commented on 406fa0c Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.