diff --git a/packages/react-core/src/components/Page/PageSection.tsx b/packages/react-core/src/components/Page/PageSection.tsx index 0ab2db8333d..4dbee130112 100644 --- a/packages/react-core/src/components/Page/PageSection.tsx +++ b/packages/react-core/src/components/Page/PageSection.tsx @@ -65,6 +65,8 @@ export interface PageSectionProps extends React.HTMLProps { * This prop should also be passed in if a heading is not being used to describe the content of the page section. */ 'aria-label'?: string; + /** Sets the base component to render. Defaults to section */ + component?: keyof JSX.IntrinsicElements; } const variantType = { @@ -98,6 +100,7 @@ export const PageSection: React.FunctionComponent = ({ hasShadowBottom = false, hasOverflowScroll = false, 'aria-label': ariaLabel, + component = 'section', ...props }: PageSectionProps) => { const { height, getVerticalBreakpoint } = React.useContext(PageContext); @@ -109,8 +112,10 @@ export const PageSection: React.FunctionComponent = ({ } }, [hasOverflowScroll, ariaLabel]); + const Component = component as any; + return ( -
= ({ > {isWidthLimited &&
{children}
} {!isWidthLimited && children} -
+ ); }; PageSection.displayName = 'PageSection'; diff --git a/packages/react-core/src/components/Page/__tests__/PageSection.test.tsx b/packages/react-core/src/components/Page/__tests__/PageSection.test.tsx index f5d2c6cce84..3bdf925f9b1 100644 --- a/packages/react-core/src/components/Page/__tests__/PageSection.test.tsx +++ b/packages/react-core/src/components/Page/__tests__/PageSection.test.tsx @@ -128,3 +128,15 @@ test('Logs a warning in the console when an aria-label is not included with hasO expect(consoleWarning).toHaveBeenCalled(); }); + +test('Renders as a section by default', () => { + render(test); + + expect(screen.getByText('test')).toHaveProperty('nodeName', 'SECTION'); +}); + +test('Renders as other elements when a different element type is passed using the component prop', () => { + render(test); + + expect(screen.getByRole('main')).toHaveTextContent('test'); +});