diff --git a/.changeset/tidy-banners-title-element.md b/.changeset/tidy-banners-title-element.md
new file mode 100644
index 00000000000..428a0e3cbc1
--- /dev/null
+++ b/.changeset/tidy-banners-title-element.md
@@ -0,0 +1,5 @@
+---
+'@primer/react': minor
+---
+
+Banner: Add support for rendering `Banner.Title` as a paragraph.
diff --git a/packages/react/src/Banner/Banner.docs.json b/packages/react/src/Banner/Banner.docs.json
index be04df252ca..f1189de6042 100644
--- a/packages/react/src/Banner/Banner.docs.json
+++ b/packages/react/src/Banner/Banner.docs.json
@@ -131,7 +131,8 @@
"props": [
{
"name": "as",
- "type": "'h2' | 'h3' | 'h4' | 'h5' | 'h6'"
+ "type": "'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'",
+ "defaultValue": "'h2'"
}
]
},
diff --git a/packages/react/src/Banner/Banner.test.tsx b/packages/react/src/Banner/Banner.test.tsx
index 73d771ad36a..b939b6c9893 100644
--- a/packages/react/src/Banner/Banner.test.tsx
+++ b/packages/react/src/Banner/Banner.test.tsx
@@ -319,7 +319,7 @@ describe('Banner', () => {
expect(screen.getByRole('heading', {level: 2, name: 'test'})).toBeInTheDocument()
})
- it('should support rendering as any heading element above level 2', () => {
+ it('should support rendering as any supported heading element', () => {
const levels = [2, 3, 4, 5, 6] as const
render(
@@ -347,6 +347,15 @@ describe('Banner', () => {
}
})
+ it('should support rendering as a paragraph element', () => {
+ render(
+
+ test paragraph
+ ,
+ )
+ expect(screen.getByText('test paragraph')).toHaveRole('paragraph')
+ })
+
it('should support a custom `className` on the container element', () => {
render(
diff --git a/packages/react/src/Banner/Banner.tsx b/packages/react/src/Banner/Banner.tsx
index 0fb19589f75..7bfd5e3e6cc 100644
--- a/packages/react/src/Banner/Banner.tsx
+++ b/packages/react/src/Banner/Banner.tsx
@@ -202,20 +202,20 @@ export const Banner = React.forwardRef(function Banner
)
})
-type HeadingElement = 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
+type TitleElement = 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'
-export type BannerTitleProps = {
+export type BannerTitleProps = {
as?: As
className?: string
-} & React.ComponentPropsWithoutRef
+} & React.ComponentPropsWithoutRef
-export function BannerTitle(props: BannerTitleProps) {
- const {as: Heading = 'h2', className, children, id, ...rest} = props
+export function BannerTitle(props: BannerTitleProps) {
+ const {as: Element = 'h2', className, children, id, ...rest} = props
const context = React.useContext(BannerContext)
const titleId = id ?? context?.titleId
return (
- (props: BannerTitleProps
{children}
-
+
)
}