Skip to content

Commit e815764

Browse files
authored
chore: Add eslint-plugin-jsx-a11y plugin (#1348)
1 parent bf5b78b commit e815764

File tree

13 files changed

+170
-37
lines changed

13 files changed

+170
-37
lines changed

eslint.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22

33
import pluginImport from 'eslint-plugin-import';
4+
import pluginJsxA11y from 'eslint-plugin-jsx-a11y';
45
import * as mdx from 'eslint-plugin-mdx';
56
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
67
import pluginReact from 'eslint-plugin-react';
@@ -450,7 +451,18 @@ export default tseslint.config(
450451
},
451452
},
452453
{
453-
plugins: { 'react': pluginReact, 'react-hooks': pluginReactHooks },
454+
plugins: {
455+
'jsx-a11y': pluginJsxA11y,
456+
},
457+
rules: {
458+
...pluginJsxA11y.configs.recommended.rules,
459+
},
460+
},
461+
{
462+
plugins: {
463+
'react': pluginReact,
464+
'react-hooks': pluginReactHooks,
465+
},
454466
languageOptions: {
455467
globals: {
456468
...globals.browser,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"eslint": "~9.14.0",
1515
"eslint-import-resolver-typescript": "~3.7.0",
1616
"eslint-plugin-import": "~2.31.0",
17+
"eslint-plugin-jsx-a11y": "~6.10.2",
1718
"eslint-plugin-mdx": "~3.1.5",
1819
"eslint-plugin-prettier": "~5.2.1",
1920
"eslint-plugin-react": "~7.37.2",

packages/fuselage/src/components/AudioPlayer/AudioPlayer.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useMergedRefs, useResizeObserver } from '@rocket.chat/fuselage-hooks';
2+
import type { TrackHTMLAttributes } from 'react';
23
import { useState, useRef, forwardRef } from 'react';
34

45
import { Box, Button, IconButton, Margins } from '../..';
@@ -57,22 +58,22 @@ const getDurationForInfinityDurationAudioFile = (
5758
/**
5859
* A Fuselage’s custom AudioPlayer.
5960
*/
60-
export const AudioPlayer = forwardRef<
61-
HTMLAudioElement,
62-
{
63-
src: string;
64-
type?: string;
65-
maxPlaybackSpeed?: number;
66-
minPlaybackSpeed?: number;
67-
playbackSpeedStep?: number;
68-
download?: boolean;
69-
playLabel?: string;
70-
pauseLabel?: string;
71-
audioPlaybackRangeLabel?: string;
72-
changePlaybackSpeedLabel?: string;
73-
downloadAudioFileLabel?: string;
74-
}
75-
>(
61+
type AudioPlayerProps = {
62+
src: string;
63+
type?: string;
64+
maxPlaybackSpeed?: number;
65+
minPlaybackSpeed?: number;
66+
playbackSpeedStep?: number;
67+
download?: boolean;
68+
playLabel?: string;
69+
pauseLabel?: string;
70+
audioPlaybackRangeLabel?: string;
71+
changePlaybackSpeedLabel?: string;
72+
downloadAudioFileLabel?: string;
73+
trackProps?: TrackHTMLAttributes<HTMLTrackElement>;
74+
};
75+
76+
export const AudioPlayer = forwardRef<HTMLAudioElement, AudioPlayerProps>(
7677
(
7778
{
7879
src,
@@ -86,6 +87,7 @@ export const AudioPlayer = forwardRef<
8687
audioPlaybackRangeLabel = 'Audio Playback Range',
8788
changePlaybackSpeedLabel = 'Change Playback Speed',
8889
downloadAudioFileLabel = 'Download Audio File',
90+
trackProps,
8991
},
9092
ref,
9193
) => {
@@ -222,6 +224,7 @@ export const AudioPlayer = forwardRef<
222224
controls
223225
>
224226
<source src={src} type={type} />
227+
<track kind='captions' {...trackProps} />
225228
</audio>
226229
</Box>
227230
);

packages/fuselage/src/components/AutoComplete/__snapshots__/AutoComplete.spec.tsx.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ exports[`[AutoComplete Rendering] renders CustomSelected without crashing 1`] =
5353
class="rcx-box rcx-box--full rcx-avatar rcx-avatar--x20"
5454
>
5555
<img
56+
alt=""
5657
aria-hidden="true"
5758
class="rcx-avatar__element rcx-avatar__element--x20"
5859
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAA
@@ -257,6 +258,7 @@ exports[`[AutoComplete Rendering] renders MultipleCustomSelected without crashin
257258
class="rcx-box rcx-box--full rcx-avatar rcx-avatar--x20"
258259
>
259260
<img
261+
alt=""
260262
aria-hidden="true"
261263
class="rcx-avatar__element rcx-avatar__element--x20"
262264
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAA
@@ -340,6 +342,7 @@ v/L21v8BT/ZVoe1UItsAAAAASUVORK5CYII="
340342
class="rcx-box rcx-box--full rcx-avatar rcx-avatar--x20"
341343
>
342344
<img
345+
alt=""
343346
aria-hidden="true"
344347
class="rcx-avatar__element rcx-avatar__element--x20"
345348
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAA

packages/fuselage/src/components/Avatar/Avatar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const Avatar = ({
1515
objectFit = false,
1616
url,
1717
className,
18+
alt,
1819
...props
1920
}: AvatarProps) => {
2021
const innerClass = [
@@ -28,7 +29,7 @@ export const Avatar = ({
2829

2930
return (
3031
<AvatarContainer size={size} className={className}>
31-
<img src={`${url}`} className={`${innerClass}`} {...props} />
32+
<img src={url} className={innerClass} alt={alt || ''} {...props} />
3233
</AvatarContainer>
3334
);
3435
};

packages/fuselage/src/components/Banner/Banner.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ const Banner = ({
7676
);
7777

7878
return (
79-
<section
79+
<div
8080
className={cx('rcx-banner')(
8181
{ [variant]: true, inline, actionable },
8282
className,
8383
)}
8484
ref={ref}
85-
role='banner'
85+
role={onAction ? 'button' : 'banner'}
86+
tabIndex={onAction ? 0 : -1}
87+
onKeyDown={(e) =>
88+
e.code === 'Enter' || (e.code === 'Space' && handleBannerClick())
89+
}
8690
onClick={handleBannerClick}
8791
{...props}
8892
>
@@ -115,7 +119,7 @@ const Banner = ({
115119
<IconButton small onClick={handleCloseButtonClick} icon='cross' />
116120
</div>
117121
)}
118-
</section>
122+
</div>
119123
);
120124
};
121125

packages/fuselage/src/components/Box/richContentInline.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ i.storyName = 'i';
3535
export const a: StoryFn<typeof Box> = () => (
3636
<>
3737
<div>
38-
<a href='#'>Normal</a>
38+
<a href='#any'>Normal</a>
3939
</div>
4040
<br />
4141
<div>
42-
<a href='#' className='is-focused'>
42+
<a href='#any' className='is-focused'>
4343
Focused
4444
</a>
4545
</div>
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
import type { AnchorHTMLAttributes, HTMLAttributes, ReactNode } from 'react';
1+
import type { AnchorHTMLAttributes, HTMLAttributes } from 'react';
22

33
type MessageGenericPreviewTitleProps = {
4-
children?: ReactNode;
54
externalUrl?: string;
65
} & HTMLAttributes<HTMLSpanElement> &
76
AnchorHTMLAttributes<HTMLAnchorElement>;
87

98
export const MessageGenericPreviewTitle = ({
109
externalUrl,
10+
children,
1111
...props
12-
}: MessageGenericPreviewTitleProps) =>
13-
externalUrl ? (
14-
<span>
12+
}: MessageGenericPreviewTitleProps) => {
13+
if (externalUrl) {
14+
return (
1515
<a
1616
className='rcx-message-generic-preview__title rcx-message-generic-preview__title-link'
1717
href={externalUrl}
1818
target='_blank'
1919
{...props}
20-
/>
21-
</span>
22-
) : (
23-
<span className='rcx-message-generic-preview__title' {...props} />
24-
);
20+
>
21+
{children}
22+
</a>
23+
);
24+
}
25+
26+
return <span className='rcx-message-generic-preview__title' {...props} />;
27+
};

packages/fuselage/src/components/Modal/__snapshots__/Modal.spec.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ exports[`[Modal Component] _WithThumb should match the snapshot 1`] = `
594594
class="rcx-box rcx-box--full rcx-avatar rcx-avatar--x28 rcx-css-trljwa"
595595
>
596596
<img
597+
alt=""
597598
class="rcx-avatar__element rcx-avatar__element--x28"
598599
src="data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="
599600
/>

packages/fuselage/src/components/Sidebar/SidebarBanner.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ export const SidebarBanner = ({
3030
{text && <div className='rcx-sidebar-banner--text'>{text}</div>}
3131
{description && (
3232
<div
33+
role={onClick ? 'link' : undefined}
34+
tabIndex={0}
3335
className={[
3436
'rcx-sidebar-banner--description',
3537
onClick && 'rcx-sidebar-banner--description--clickable',
3638
]
3739
.filter(Boolean)
3840
.join(' ')}
3941
onClick={onClick}
42+
onKeyDown={(e) => e.key === 'Enter' && onClick?.()}
4043
>
4144
{description}
4245
</div>

0 commit comments

Comments
 (0)