Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/react-core/src/components/Page/PageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface PageSectionProps extends React.HTMLProps<HTMLDivElement> {
* 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 = {
Expand Down Expand Up @@ -98,6 +100,7 @@ export const PageSection: React.FunctionComponent<PageSectionProps> = ({
hasShadowBottom = false,
hasOverflowScroll = false,
'aria-label': ariaLabel,
component = 'section',
...props
}: PageSectionProps) => {
const { height, getVerticalBreakpoint } = React.useContext(PageContext);
Expand All @@ -109,8 +112,10 @@ export const PageSection: React.FunctionComponent<PageSectionProps> = ({
}
}, [hasOverflowScroll, ariaLabel]);

const Component = component as any;

return (
<section
<Component
{...props}
className={css(
variantType[type],
Expand All @@ -133,7 +138,7 @@ export const PageSection: React.FunctionComponent<PageSectionProps> = ({
>
{isWidthLimited && <div className={css(styles.pageMainBody)}>{children}</div>}
{!isWidthLimited && children}
</section>
</Component>
);
};
PageSection.displayName = 'PageSection';
Original file line number Diff line number Diff line change
Expand Up @@ -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(<PageSection>test</PageSection>);

expect(screen.getByText('test')).toHaveProperty('nodeName', 'SECTION');
});

test('Renders as other elements when a different element type is passed using the component prop', () => {
render(<PageSection component="main">test</PageSection>);

expect(screen.getByRole('main')).toHaveTextContent('test');
});