diff --git a/src/__tests__/cover-hero-test.tsx b/src/__tests__/cover-hero-test.tsx index 2d9ea5231..bce8fc7f0 100644 --- a/src/__tests__/cover-hero-test.tsx +++ b/src/__tests__/cover-hero-test.tsx @@ -5,8 +5,8 @@ import {makeTheme} from './test-utils'; import {render, screen} from '@testing-library/react'; import ThemeContextProvider from '../theme-context-provider'; -const pretitleFirst = 'HeadlinePretitleTitleDescription'; -const titleFirst = 'HeadlineTitlePretitleDescription'; +const pretitleFirst = 'PretitleHeadlineTitleDescription'; +const titleFirst = 'TitleHeadlinePretitleDescription'; test.each` pretitleAs | titleAs | expectedOrder diff --git a/src/__tests__/header-test.tsx b/src/__tests__/header-test.tsx index 5926475f3..31de0a8f6 100644 --- a/src/__tests__/header-test.tsx +++ b/src/__tests__/header-test.tsx @@ -4,8 +4,8 @@ import {makeTheme} from './test-utils'; import {render, screen} from '@testing-library/react'; import ThemeContextProvider from '../theme-context-provider'; -const pretitleFirst = 'HeadlinePretitleTitleDescription'; -const titleFirst = 'HeadlineTitlePretitleDescription'; +const pretitleFirst = 'PretitleHeadlineTitleDescription'; +const titleFirst = 'TitleHeadlinePretitleDescription'; test.each` pretitleAs | titleAs | expectedOrder diff --git a/src/__tests__/hero-test.tsx b/src/__tests__/hero-test.tsx index 491b71ac1..c93a08832 100644 --- a/src/__tests__/hero-test.tsx +++ b/src/__tests__/hero-test.tsx @@ -5,8 +5,8 @@ import {makeTheme} from './test-utils'; import {render, screen} from '@testing-library/react'; import ThemeContextProvider from '../theme-context-provider'; -const pretitleFirst = 'HeadlinePretitleTitleDescription'; -const titleFirst = 'HeadlineTitlePretitleDescription'; +const pretitleFirst = 'PretitleHeadlineTitleDescription'; +const titleFirst = 'TitleHeadlinePretitleDescription'; test.each` pretitleAs | titleAs | expectedOrder diff --git a/src/cover-hero.tsx b/src/cover-hero.tsx index 154d3e80d..d2096ca0f 100644 --- a/src/cover-hero.tsx +++ b/src/cover-hero.tsx @@ -123,7 +123,7 @@ const CoverHero = React.forwardRef( ) : undefined; - const titleContent = ( + const titleContent = title ? ( ( > {title} - ); + ) : undefined; + + const headlineContent = headline ? ( +
+ + {headline} + +
+ ) : undefined; const mainContent = (
- {headline && ( - - {headline} - - )} {/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */}
{isBiggerHeading(titleAs, pretitleAs) ? ( <> {titleContent} + {headlineContent} {pretitleContent && (
( {pretitleContent}
)} + {headlineContent} {titleContent} )} diff --git a/src/header.tsx b/src/header.tsx index 1efbf329a..149e05b1a 100644 --- a/src/header.tsx +++ b/src/header.tsx @@ -87,30 +87,29 @@ export const Header = ({ ) ) : undefined; + const headlineContent = headline ? ( + // assuming that the headline will always be followed by one of: pretitle, title, description +
+ {headline} +
+ ) : undefined; + return ( {(title || pretitle || description) && ( {/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */}
- {headline && ( -
- {headline} -
- )} - {isBiggerHeading(titleAs, pretitleAs) ? ( <> {titleContent && ( -
- {titleContent} -
+
{titleContent}
)} + {headlineContent} {pretitleContent && ( -
{pretitleContent}
+
+ {pretitleContent} +
)} ) : ( @@ -120,6 +119,7 @@ export const Header = ({ {pretitleContent}
)} + {headlineContent} {titleContent && (
{titleContent}
)} diff --git a/src/hero.tsx b/src/hero.tsx index d5cc221a6..3fdaee344 100644 --- a/src/hero.tsx +++ b/src/hero.tsx @@ -91,17 +91,23 @@ const HeroContent = ({ ) : undefined; + const headlineContent = headline ? ( + // assuming that the headline will always be followed by one of: pretitle, title, subtitle, description +
+ {headline} +
+ ) : undefined; + return (
- {headline &&
{headline}
} - {/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */}
{isBiggerHeading(titleAs, pretitleAs) ? ( <> {titleContent} + {headlineContent} {pretitleContent && (
{pretitleContent} @@ -113,6 +119,7 @@ const HeroContent = ({ {pretitleContent && (
{pretitleContent}
)} + {headlineContent} {titleContent} )}