Skip to content

Commit 6f0288e

Browse files
Fix contents list missing ARIA attributes
1 parent 32c0900 commit 6f0288e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/components/navigation/contents-list/ContentsList.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ interface ContentsListItemProps extends HTMLProps<HTMLAnchorElement> {
66
}
77

88
const ContentsListItem: FC<ContentsListItemProps> = ({ className, current, ...rest }) => (
9-
<li className={classNames('nhsuk-contents-list__item', className)}>
9+
<li
10+
className={classNames('nhsuk-contents-list__item', className)}
11+
aria-current={current ? 'page' : undefined}
12+
>
1013
{current ? (
1114
<span className="nhsuk-contents-list__current" {...rest} />
1215
) : (
@@ -27,10 +30,16 @@ const ContentsListComponent: ContentsListComponent = ({
2730
className,
2831
children,
2932
role = 'navigation',
33+
'aria-label': ariaLabel = 'Pages in this guide',
3034
visuallyHiddenText = 'Contents',
3135
...rest
3236
}) => (
33-
<nav className={classNames('nhsuk-contents-list', className)} role={role} {...rest}>
37+
<nav
38+
className={classNames('nhsuk-contents-list', className)}
39+
role={role}
40+
aria-label={ariaLabel}
41+
{...rest}
42+
>
3443
<h2 className="nhsuk-u-visually-hidden">{visuallyHiddenText}</h2>
3544
<ol className="nhsuk-contents-list__list">{children}</ol>
3645
</nav>

src/components/navigation/contents-list/__tests__/__snapshots__/ContentsList.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ exports[`ContentsList ContentsList.Item matches snapshot: ContentsList.Item 1`]
1717
exports[`ContentsList matches snapshot: ContentsList 1`] = `
1818
<div>
1919
<nav
20+
aria-label="Pages in this guide"
2021
class="nhsuk-contents-list"
2122
role="navigation"
2223
>

stories/Navigation/ContentsList.stories.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Meta, StoryObj } from '@storybook/react';
2121
* const Element = () => {
2222
* return (
2323
* <ContentsList aria-label="Pages in this guide">
24-
* <ContentsList.Item current aria-current="page">
24+
* <ContentsList.Item current>
2525
* What is AMD?
2626
* </ContentsList.Item>
2727
* <ContentsList.Item href="https://www.nhs.uk/conditions/age-related-macular-degeneration-amd/symptoms/">
@@ -53,9 +53,7 @@ ContentsList.Item.displayName = 'ContentsList.Item';
5353
export const Standard: Story = {
5454
render: (args) => (
5555
<ContentsList aria-label="Pages in this guide">
56-
<ContentsList.Item current aria-current="page">
57-
What is AMD?
58-
</ContentsList.Item>
56+
<ContentsList.Item current>What is AMD?</ContentsList.Item>
5957
<ContentsList.Item href="https://www.nhs.uk/conditions/age-related-macular-degeneration-amd/symptoms/">
6058
Symptoms
6159
</ContentsList.Item>

0 commit comments

Comments
 (0)