Skip to content

Commit 79d8c91

Browse files
authored
fix(ui): Learn Page Landmark Accessibility issues (#8551)
* fix(ui): Learn Page Landmark Accessibility issues * fix(ui): remove role attribute from Banner component for accessibility compliance * fix(ui): enhance aria label for Banner and Metabar as a prop * fix(i18n): update banner aria labels for improved accessibility
1 parent 8f8f8c5 commit 79d8c91

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

apps/site/components/withBanner.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ArrowUpRightIcon } from '@heroicons/react/24/outline';
22
import Banner from '@node-core/ui-components/Common/Banner';
3+
import { useTranslations } from 'next-intl';
34

45
import Link from '#site/components/Link';
56
import { siteConfig } from '#site/next.json.mjs';
@@ -9,10 +10,16 @@ import type { FC } from 'react';
910

1011
const WithBanner: FC<{ section: string }> = ({ section }) => {
1112
const banner = siteConfig.websiteBanners[section];
13+
const t = useTranslations();
1214

1315
if (banner && dateIsBetween(banner.startDate, banner.endDate)) {
16+
const bannerType = banner.type || 'default';
17+
1418
return (
15-
<Banner type={banner.type}>
19+
<Banner
20+
type={banner.type}
21+
aria-label={t(`components.banner.${bannerType}`)}
22+
>
1623
{banner.link ? (
1724
<Link href={banner.link}>{banner.text}</Link>
1825
) : (

apps/site/components/withMetaBar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const WithMetaBar: FC = () => {
4444
<MetaBar
4545
heading={t('components.metabar.tableOfContents')}
4646
as={Link}
47+
aria-label={t('components.metabar.metadata')}
4748
items={{
4849
[t('components.metabar.lastUpdated')]: lastUpdated,
4950
[t('components.metabar.readingTime')]: readingTimeText,

packages/i18n/src/locales/en.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,13 @@
280280
"contribute": "Contribute",
281281
"contributeText": "Edit this page",
282282
"viewAs": "View as",
283-
"tableOfContents": "Table of Contents"
283+
"tableOfContents": "Table of Contents",
284+
"metadata": "Article metadata"
285+
},
286+
"banner": {
287+
"default": "Announcement",
288+
"warning": "Warning notification",
289+
"error": "Error notification"
284290
},
285291
"search": {
286292
"searchPlaceholder": "Start typing...",

packages/ui-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@node-core/ui-components",
3-
"version": "1.5.4",
3+
"version": "1.5.5",
44
"type": "module",
55
"exports": {
66
"./*": [
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
import type { FC, PropsWithChildren } from 'react';
1+
import type { FC, HTMLAttributes, PropsWithChildren } from 'react';
22

33
import styles from './index.module.css';
44

55
export type BannerProps = {
66
type?: 'default' | 'warning' | 'error';
7-
};
7+
} & HTMLAttributes<HTMLElement>;
88

99
const Banner: FC<PropsWithChildren<BannerProps>> = ({
1010
type = 'default',
1111
children,
12+
...props
1213
}) => (
13-
<div className={`${styles.banner} ${styles[type] || styles.default}`}>
14+
<section
15+
className={`${styles.banner} ${styles[type] || styles.default}`}
16+
{...props}
17+
>
1418
{children}
15-
</div>
19+
</section>
1620
);
1721

1822
export default Banner;

packages/ui-components/src/Containers/MetaBar/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Fragment, useMemo } from 'react';
22

33
import type { LinkLike } from '#ui/types';
44
import type { Heading } from '@vcarl/remark-headings';
5-
import type { FC } from 'react';
5+
import type { FC, HTMLAttributes } from 'react';
66

77
import styles from './index.module.css';
88

@@ -14,13 +14,14 @@ type MetaBarProps = {
1414
};
1515
as?: LinkLike;
1616
heading: string;
17-
};
17+
} & HTMLAttributes<HTMLElement>;
1818

1919
const MetaBar: FC<MetaBarProps> = ({
2020
items,
2121
headings,
2222
as: Component = 'a',
2323
heading,
24+
...props
2425
}) => {
2526
// The default depth of headings to display in the table of contents.
2627
const { minDepth = 2, items: headingItems = [] } = headings || {};
@@ -31,7 +32,7 @@ const MetaBar: FC<MetaBarProps> = ({
3132
);
3233

3334
return (
34-
<div className={styles.wrapper}>
35+
<aside className={styles.wrapper} {...props}>
3536
<dl>
3637
{Object.entries(items)
3738
.filter(([, value]) => !!value)
@@ -65,7 +66,7 @@ const MetaBar: FC<MetaBarProps> = ({
6566
</>
6667
)}
6768
</dl>
68-
</div>
69+
</aside>
6970
);
7071
};
7172

0 commit comments

Comments
 (0)