Import
import { Header } from '@contentful/f36-components';// orimport { Header } from '@contentful/f36-header';
Examples
Basic Header with title
function HeaderExample() {return <Header title="Content Types" />;}
With breadcrumbs & back button
function HeaderExample() {return (<Headertitle="Article"withBackButton={true}backButtonProps={{ onClick: () => console.log('back button click') }}breadcrumbs={[{content: 'Content Types',url: '#',onClick: () => console.log('Content Types clicked'),},]}/>);}
With actions
function HeaderExample() {return (<Headertitle="Article"actions={<FlexalignItems="center"gap={tokens.spacingS}justifyContent="flex-end"><Button variant="secondary" size="small">Suggest Alternatives</Button><Button variant="positive" size="small">Save</Button></Flex>}/>);}
With filters
function HeaderExample() {return (<Headertitle="Entries"filters={<TextInput size="small" placeholder="Search" />}/>);}
Header areas
prop | description | Expected content |
---|---|---|
breadcrumbs | An (optional) list of navigable links to prepend to the current title. | Array of breadcumbs |
title | The title of the element this header pertains to. If handed over a string, it will wrap it in a heading element (default: h1) | Title string or ReactElement |
metadata | Optional additional information to display in the header, will appear after the title. | Text, Badge, Tag |
filters | Optional element displayed in the center of the header, typically used to render refinement/search UI. | TextInput, Select, Search |
actions | Optional elements to display as complementary actions (e.g. buttons) related to the current page/route. | Button, IconButton, Dropdown |
Accessibility
- The Header component renders a
<header>
landmark and a heading (<h1>
by default). Use the title prop for a meaningful heading, and adjust the heading level withtitleProps.as
as needed for your page structure. - If using multiple headers, use the
as
prop to avoid duplicate landmarks and keep the hierarchy of the content integer. - Breadcrumbs and back buttons improve navigation for all users. Ensure they have descriptive, accessible labels.
- All interactive elements in actions and filters must be keyboard accessible and clearly labeled.
Props (API reference)
Open in StorybookName | Type | Default |
---|---|---|
actions | ReactElement<any, string | JSXElementConstructor<any>> ReactElement<any, string | JSXElementConstructor<any>>[] Optional JSX children to display as complementary actions (e.g. buttons) related to the current page/route. | |
as | HTML Tag or React Component (e.g. div, span, etc) | |
backButtonProps | BackButtonProps Ensure that backbutton props can not be passed when `withBackButton` is false. This is to prevent confusion, as the back button will not be rendered. Props to spread on the back button. You almost certainly want to pass an `onClick` handler. | |
breadcrumbs | Breadcrumb[] An (optional) list of navigable links to prepend to the current title. | |
filters | ReactElement<any, string | JSXElementConstructor<any>> An (optional) element displayed in the center of the header, typically used to render refinement/search UI. | |
metadata | string number false true {} ReactElement<any, string | JSXElementConstructor<any>> ReactNodeArray ReactPortal | |
title | string ReactElement<any, string | JSXElementConstructor<any>> The title of the element this header pertains to. | |
titleProps | { as?: HeadingElement; size?: "medium" | "large"; } | |
withBackButton | false true If `true`, renders a leading back button within the header. |