Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with the footer copyright not being rendered in the correct location if there are multiple link columns #223

Merged
merged 1 commit into from
May 20, 2024
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
14 changes: 12 additions & 2 deletions src/components/navigation/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ const Footer: Footer = ({ className, children, visuallyHiddenText = 'Support lin
const footerCols = Children.toArray(children).filter((child) =>
childIsOfComponentType(child, FooterList),
);
const footerCopyright = Children.toArray(children).filter((child) =>
childIsOfComponentType(child, FooterCopyright),
);

let newChildren = children;
let newChildren;
const footerHasMultipleColumns = footerCols.length > 1;

if (footerCols.length === 1) {
if (footerHasMultipleColumns) {
// Remove the copyright from being rendered inside the 'nhsuk-footer' div
newChildren = Children.toArray(children).filter(
(child) => !childIsOfComponentType(child, FooterCopyright),
);
} else {
newChildren = Children.map(children, (child) =>
childIsOfComponentType(child, FooterList)
? cloneElement(child, { singleColumn: true })
Expand All @@ -79,6 +88,7 @@ const Footer: Footer = ({ className, children, visuallyHiddenText = 'Support lin
<h2 className="nhsuk-u-visually-hidden">{visuallyHiddenText}</h2>
) : null}
<div className="nhsuk-footer">{newChildren}</div>
{footerHasMultipleColumns ? <div>{footerCopyright}</div> : undefined}
</Container>
</div>
</footer>
Expand Down
36 changes: 36 additions & 0 deletions src/components/navigation/footer/__tests__/Footer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,42 @@ describe('Footer', () => {
);
});

it('Renders the copyright within the nhsuk-footer when there is only one column', () => {
const { container } = render(
<Footer>
<Footer.List>
<Footer.ListItem id="test-listItem"></Footer.ListItem>
</Footer.List>
<Footer.Copyright>This is the copyright</Footer.Copyright>
</Footer>,
);
expect(container.querySelectorAll('.nhsuk-footer__copyright').length).toBe(1);
expect(
container.querySelector('.nhsuk-footer')?.querySelector('.nhsuk-footer__copyright'),
).not.toBeNull();
});

it('Renders the copyright outside of the nhsuk-footer when there is more than one column', () => {
const { container } = render(
<Footer>
<Footer.List>
<Footer.ListItem id="test-listItem"></Footer.ListItem>
</Footer.List>
<Footer.List>
<Footer.ListItem id="test-listItem2"></Footer.ListItem>
</Footer.List>
<Footer.Copyright>This is the copyright</Footer.Copyright>
</Footer>,
);
expect(container.querySelectorAll('.nhsuk-footer__copyright').length).toBe(1);
expect(
container.querySelector('.nhsuk-width-container')?.querySelector('.nhsuk-footer__copyright'),
).not.toBeNull();
expect(
container.querySelector('.nhsuk-footer')?.querySelector('.nhsuk-footer__copyright'),
).toBeNull();
});

it('Does not include the single column class on ListItem when there is more than one column', () => {
const { container } = render(
<Footer>
Expand Down
2 changes: 1 addition & 1 deletion stories/Navigation/Footer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const WithLinksArrangedInColumns: Story = {
<Footer.ListItem href="#">Profile editor login</Footer.ListItem>
</Footer.List>

<Footer.List>
<Footer.List className="nhsuk-footer__meta">
<Footer.ListItem href="#">About us</Footer.ListItem>
<Footer.ListItem href="#">Accessibility statement</Footer.ListItem>
<Footer.ListItem href="#">Our policies</Footer.ListItem>
Expand Down
Loading