Skip to content

Commit

Permalink
Merge pull request #10397 from bbc/topic-promos-first-curation
Browse files Browse the repository at this point in the history
Visually-hidden h2 for first topic curation
  • Loading branch information
rebeccamcginn authored Nov 9, 2022
2 parents dfa4da9 + 55b6328 commit fbea868
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/app/pages/TopicPage/Curation/Subhead/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Component = ({ service, variant }: Props) => {
const WithLink = ({ service, variant }: Props) => {
return (
<ServiceContextProvider service={service} variant={variant}>
<Subheading href="https://bbc.com">
<Subheading link="https://bbc.com">
{services[service][variant].translations.relatedContent}
</Subheading>
</ServiceContextProvider>
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/TopicPage/Curation/Subhead/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { Services } from '../../../../models/types/global';

interface Props {
service?: Services;
href?: string;
link?: string;
}

/* eslint-disable react/prop-types */
const SubheadWithContext = ({
children = '',
href = '',
link = '',
service = 'mundo',
}: PropsWithChildren<Props>) => (
<ServiceContextProvider service={service}>
<Subhead href={href}>{children}</Subhead>
<Subhead link={link}>{children}</Subhead>
</ServiceContextProvider>
);

Expand All @@ -33,7 +33,7 @@ describe('Curation Subhead Component', () => {

it('should render children within an h2', () => {
const { container } = render(
<SubheadWithContext href="https://bbc.com">My Text</SubheadWithContext>,
<SubheadWithContext link="https://bbc.com">My Text</SubheadWithContext>,
);

const anchorElement = container.querySelector('a');
Expand Down
10 changes: 5 additions & 5 deletions src/app/pages/TopicPage/Curation/Subhead/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { LeftChevron, RightChevron } from '../../../../components/icons';
import { ServiceContext } from '../../../../contexts/ServiceContext';

interface Props {
href?: string;
link?: string;
a11yID?: string;
}

const Subhead = ({ children, href, a11yID }: PropsWithChildren<Props>) => {
const Subhead = ({ children, link, a11yID }: PropsWithChildren<Props>) => {
const { service, script, dir } = useContext(ServiceContext);

const Wrapper = href
const Wrapper = link
? ({ children: innerChildren }: PropsWithChildren<Props>) => (
<a href={href}>
<a href={link}>
<span>{innerChildren}</span>
{dir === 'ltr' ? <RightChevron /> : <LeftChevron />}
</a>
Expand All @@ -29,6 +29,6 @@ const Subhead = ({ children, href, a11yID }: PropsWithChildren<Props>) => {
);
};

Subhead.defaultProps = { href: '', a11yID: '' };
Subhead.defaultProps = { link: '', a11yID: '' };

export default Subhead;
20 changes: 14 additions & 6 deletions src/app/pages/TopicPage/Curation/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { arrayOf, oneOf, shape, string, number } from 'prop-types';
import pathOr from 'ramda/src/pathOr';
import VisuallyHiddenText from '#psammead/psammead-visually-hidden-text/src';
import CurationGrid from './CurationGrid';
import Subheading from './Subhead';

Expand Down Expand Up @@ -40,12 +41,19 @@ const Curation = ({
const createID = titleText => {
return titleText.replaceAll(' ', '-');
};
return curationLength > 1 && (title || position === 0) ? (
<section aria-labelledby={createID(title || topStoriesTitle)} role="region">
<Subheading a11yID={createID(title || topStoriesTitle)} href={link}>
{title}
</Subheading>
<Component promos={promos} headingLevel={headingLevel} />
const isFirstCuration = position === 0;
const SubheadingComponent = isFirstCuration ? VisuallyHiddenText : Subheading;
const id = createID(title || topStoriesTitle);

return curationLength > 1 && (title || isFirstCuration) ? (
<section aria-labelledby={id} role="region">
<SubheadingComponent as="h2" a11yID={id} id={id} link={link}>
{title || topStoriesTitle}
</SubheadingComponent>
<Component
promos={promos}
headingLevel={isFirstCuration ? 3 : headingLevel}
/>
</section>
) : (
<Component promos={promos} headingLevel={headingLevel} />
Expand Down

0 comments on commit fbea868

Please sign in to comment.