Skip to content

Commit b647f97

Browse files
committed
Fix issue with the footer copyright not being rendered in the correct location if there are multiple link columns
1 parent e8c110c commit b647f97

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/components/navigation/footer/Footer.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,19 @@ const Footer: Footer = ({ className, children, visuallyHiddenText = 'Support lin
6060
const footerCols = Children.toArray(children).filter((child) =>
6161
childIsOfComponentType(child, FooterList),
6262
);
63+
const footerCopyright = Children.toArray(children).filter((child) =>
64+
childIsOfComponentType(child, FooterCopyright),
65+
);
6366

64-
let newChildren = children;
67+
let newChildren;
68+
const footerHasMultipleColumns = footerCols.length > 1;
6569

66-
if (footerCols.length === 1) {
70+
if (footerHasMultipleColumns) {
71+
// Remove the copyright from being rendered inside the 'nhsuk-footer' div
72+
newChildren = Children.toArray(children).filter(
73+
(child) => !childIsOfComponentType(child, FooterCopyright),
74+
);
75+
} else {
6776
newChildren = Children.map(children, (child) =>
6877
childIsOfComponentType(child, FooterList)
6978
? cloneElement(child, { singleColumn: true })
@@ -79,6 +88,7 @@ const Footer: Footer = ({ className, children, visuallyHiddenText = 'Support lin
7988
<h2 className="nhsuk-u-visually-hidden">{visuallyHiddenText}</h2>
8089
) : null}
8190
<div className="nhsuk-footer">{newChildren}</div>
91+
{footerHasMultipleColumns ? <div>{footerCopyright}</div> : undefined}
8292
</Container>
8393
</div>
8494
</footer>

src/components/navigation/footer/__tests__/Footer.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,42 @@ describe('Footer', () => {
4242
);
4343
});
4444

45+
it('Renders the copyright within the nhsuk-footer when there is only one column', () => {
46+
const { container } = render(
47+
<Footer>
48+
<Footer.List>
49+
<Footer.ListItem id="test-listItem"></Footer.ListItem>
50+
</Footer.List>
51+
<Footer.Copyright>This is the copyright</Footer.Copyright>
52+
</Footer>,
53+
);
54+
expect(container.querySelectorAll('.nhsuk-footer__copyright').length).toBe(1);
55+
expect(
56+
container.querySelector('.nhsuk-footer')?.querySelector('.nhsuk-footer__copyright'),
57+
).not.toBeNull();
58+
});
59+
60+
it('Renders the copyright outside of the nhsuk-footer when there is more than one column', () => {
61+
const { container } = render(
62+
<Footer>
63+
<Footer.List>
64+
<Footer.ListItem id="test-listItem"></Footer.ListItem>
65+
</Footer.List>
66+
<Footer.List>
67+
<Footer.ListItem id="test-listItem2"></Footer.ListItem>
68+
</Footer.List>
69+
<Footer.Copyright>This is the copyright</Footer.Copyright>
70+
</Footer>,
71+
);
72+
expect(container.querySelectorAll('.nhsuk-footer__copyright').length).toBe(1);
73+
expect(
74+
container.querySelector('.nhsuk-width-container')?.querySelector('.nhsuk-footer__copyright'),
75+
).not.toBeNull();
76+
expect(
77+
container.querySelector('.nhsuk-footer')?.querySelector('.nhsuk-footer__copyright'),
78+
).toBeNull();
79+
});
80+
4581
it('Does not include the single column class on ListItem when there is more than one column', () => {
4682
const { container } = render(
4783
<Footer>

stories/Navigation/Footer.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const WithLinksArrangedInColumns: Story = {
6161
<Footer.ListItem href="#">Profile editor login</Footer.ListItem>
6262
</Footer.List>
6363

64-
<Footer.List>
64+
<Footer.List className="nhsuk-footer__meta">
6565
<Footer.ListItem href="#">About us</Footer.ListItem>
6666
<Footer.ListItem href="#">Accessibility statement</Footer.ListItem>
6767
<Footer.ListItem href="#">Our policies</Footer.ListItem>

0 commit comments

Comments
 (0)