Skip to content

Commit e4c7c3a

Browse files
sorted h2 ids
added in more storybooks for different scenarios
1 parent fa24b40 commit e4c7c3a

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

dotcom-rendering/src/components/ProductElement.stories.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,39 @@ export const withoutHeading: StoryFn = () => {
349349
);
350350
};
351351

352+
export const emptyHeadingsOnly: StoryFn = () => {
353+
return (
354+
<>
355+
<ProductElement
356+
product={{
357+
...product,
358+
primaryHeading: '',
359+
secondaryHeading: 'Secondary heading only',
360+
}}
361+
format={{
362+
design: ArticleDesign.Review,
363+
display: ArticleDisplay.Showcase,
364+
theme: Pillar.Lifestyle,
365+
}}
366+
ArticleElementComponent={ArticleElementComponent}
367+
/>
368+
<ProductElement
369+
product={{
370+
...product,
371+
primaryHeading: 'Primary Heading',
372+
secondaryHeading: '',
373+
}}
374+
format={{
375+
design: ArticleDesign.Review,
376+
display: ArticleDisplay.Showcase,
377+
theme: Pillar.Lifestyle,
378+
}}
379+
ArticleElementComponent={ArticleElementComponent}
380+
/>
381+
</>
382+
);
383+
};
384+
352385
export const displayTypeProductCardOnly: StoryFn = () => {
353386
return (
354387
<>

dotcom-rendering/src/components/ProductElement.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,9 @@ export const ProductElement = ({
5858
format: ArticleFormat;
5959
}) => {
6060
const subheadingHtml = parseHtml(
61-
[
62-
product.primaryHeading
63-
? `<h2 id="${product.h2Id ?? product.elementId}-primary">${
64-
product.primaryHeading
65-
}</h2>`
66-
: '',
67-
product.secondaryHeading
68-
? `<h2 id="${product.h2Id ?? product.elementId}-secondary">${
69-
product.secondaryHeading
70-
}</h2>`
71-
: '',
72-
].join(''),
61+
`<h2 id="${product.h2Id ?? product.elementId}">${
62+
product.primaryHeading ? `${product.primaryHeading}</br>` : ''
63+
} ${product.secondaryHeading || ''}</h2>`,
7364
);
7465

7566
const isSubheading = subheadingHtml.textContent

0 commit comments

Comments
 (0)