Skip to content

Commit

Permalink
chore: add eslint a11y rules (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
korvin89 authored Jun 1, 2023
1 parent 0782734 commit 717e720
Show file tree
Hide file tree
Showing 24 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": ["@gravity-ui/eslint-config", "@gravity-ui/eslint-config/client", "@gravity-ui/eslint-config/prettier"],
"extends": [
"@gravity-ui/eslint-config",
"@gravity-ui/eslint-config/client",
"@gravity-ui/eslint-config/prettier",
"@gravity-ui/eslint-config/a11y"
],
"root": true,
"rules": {
"react/jsx-fragments": ["error", "element"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const Interactive: Story<ArrowToggleProps> = (args) => {
const direction = directions[directionIndex % directions.length];

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<span onClick={() => setDirectionIndex(directionIndex + 1)} style={{cursor: 'pointer'}}>
<ArrowToggle {...args} size={32} direction={direction} /> <h3>{direction}</h3>
</span>
Expand Down
1 change: 1 addition & 0 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const Card = React.forwardRef<HTMLDivElement, CardProps>(function Card(pr
const defaultView = isTypeContainer || isTypeSelection ? 'outlined' : undefined;

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div
ref={ref}
className={b(
Expand Down
1 change: 1 addition & 0 deletions src/components/DropdownMenu/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const DropdownMenu = <T,>({

return (
<DropdownMenuContext.Provider value={contextValue}>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div
ref={anchorRef}
className={cnDropdownMenu('switcher-wrapper', switcherWrapperClassName)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const Label = React.forwardRef<HTMLDivElement, LabelProps>(function Label
}

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div
ref={ref}
onClick={hasOnClick ? onClick : undefined}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const Link = React.forwardRef<HTMLElement, LinkProps>(function Link(
const relProp = target === '_blank' && !rel ? 'noopener noreferrer' : rel;

return (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
{...(extraProps as React.AnchorHTMLAttributes<HTMLAnchorElement>)}
{...commonProps}
Expand All @@ -85,6 +86,7 @@ export const Link = React.forwardRef<HTMLElement, LinkProps>(function Link(
{...(extraProps as React.HTMLAttributes<HTMLSpanElement>)}
{...commonProps}
ref={ref as React.Ref<HTMLSpanElement>}
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
tabIndex={0}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class List<T = unknown> extends React.Component<ListProps<T>, ListState<T
return (
<MobileContext.Consumer>
{({mobile}) => (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
className={b({mobile}, className)}
data-qa={qa}
Expand Down Expand Up @@ -245,6 +246,7 @@ export class List<T = unknown> extends React.Component<ListProps<T>, ListState<T
value={filter}
hasClear={true}
onUpdate={this.onFilterUpdate}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={autoFocus}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/List/components/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ListItem<T = unknown> extends React.Component<ListItemProps<T>> {
this.props;

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<div
role="listitem"
data-qa={active ? ListQa.ACTIVE_ITEM : undefined}
Expand Down
2 changes: 2 additions & 0 deletions src/components/PersonaWrap/PersonaWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export function PersonaWrap({
const closeable = Boolean(onClose);
return (
<div className={b({size, theme, clickable, closeable, empty: isEmpty}, className)}>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div className={b('main')} onClick={onClick}>
{avatar && <div className={b('avatar')}>{avatar}</div>}
<div className={b('text')}>{children}</div>
</div>
{onClose && (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div className={b('close')} onClick={onClose}>
<Icon data={CrossIcon} size={8} />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/Popover/components/Trigger/Trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ export const Trigger = ({
toggleTooltip();
};

// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
return <span onClick={handleClick}>{children}</span>;
};
1 change: 1 addition & 0 deletions src/components/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function Popup({
{...containerProps}
className={bWrapper({open})}
>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div
onClick={onClick}
onMouseEnter={onMouseEnter}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Popup/__stories__/Popup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const Position: Story<PopupProps> = (args) => {
const anchorRef = useVirtualElementRef({rect: {top, left}});
return (
<div>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label style={{display: 'flex', alignItems: 'center'}}>
x:
<TextInput
Expand All @@ -107,6 +108,7 @@ export const Position: Story<PopupProps> = (args) => {
style={{width: 100}}
/>
</label>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label style={{display: 'flex', alignItems: 'center'}}>
y:
<TextInput
Expand Down
1 change: 1 addition & 0 deletions src/components/Sheet/SheetContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class SheetContent extends React.Component<SheetContentInnerProps, SheetContentS

return (
<React.Fragment>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<div
ref={this.veilRef}
className={sheetBlock('veil', veilTransitionMod)}
Expand Down
1 change: 1 addition & 0 deletions src/components/StoreBadge/StoreBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function StoreBadge({
alt,
}: StoreBadgeProps) {
if (!url) {
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
return <img className={b({platform, lang}, className)} onClick={onClick} alt={alt} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const PreviewItem = ({active, disabled, groupIndex, media, onSelectGroup}: Previ
);

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div
className={b('stories-preview-item', {
active,
Expand Down Expand Up @@ -195,6 +196,7 @@ export const StoriesPreview = ({

if (groups.length < maxSliderItemsCount) {
return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div className={b()} onClick={handleClose}>
<StoriesPreviewList
groupIndex={groupIndex}
Expand All @@ -206,6 +208,7 @@ export const StoriesPreview = ({
}

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div className={b()} onClick={handleClose}>
<StoriesPreviewListWithSlider
maxSliderItemsCount={maxSliderItemsCount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {

return (
<div className={b(null, className)}>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div className={b('control')} ref={refControl} onClick={handleControlClick}>
{switcher || (
<Button disabled={disabled}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export function withTableSorting<I extends TableDataItem, E extends {} = {}>(
}

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div
className={b('sort', {active: Boolean(sortOrder)})}
onClick={this.handleColumnSortClick.bind(this, column)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Tabs/__stories__/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const WithWrapTo = Template.bind({});
WithWrapTo.args = {
wrapTo(_item: TabsItemProps, node: React.ReactNode) {
return (
// eslint-disable-next-line jsx-a11y/anchor-is-valid
<a key={_item.id} href="#">
{node}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const AdditionalContent = React.forwardRef<HTMLDivElement, Props>(functio
}

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div ref={ref} className={b('additional-content', {placement})} onClick={onClick}>
{children}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/TextInput/InputControl/InputControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function InputControl(props: InputControlProps) {
placeholder={placeholder}
value={value}
defaultValue={defaultValue}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={autoFocus}
autoComplete={autoComplete}
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function TextAreaControl(props: TextAreaControlProps) {
value={value}
defaultValue={defaultValue}
rows={textareaRows}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={autoFocus}
autoComplete={autoComplete}
onChange={handleChange}
Expand Down
1 change: 1 addition & 0 deletions src/components/UserAvatar/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function UserAvatar({
onClick,
}: UserAvatarProps) {
return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div title={title} className={b({size}, className)} onClick={onClick}>
<img
className={b('figure')}
Expand Down
2 changes: 2 additions & 0 deletions src/components/utils/__tests__/xpath.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint jsx-a11y/click-events-have-key-events: 0, jsx-a11y/no-static-element-interactions: 0 */

import React from 'react';

import {render, screen} from '@testing-library/react';
Expand Down
1 change: 1 addition & 0 deletions src/demo/colors/ColorPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function ColorPanel(props: ColorPanelProps) {

return (
<div className={`color-panel color-panel_bg_${BACKGROUND_LIST[currentBackgroundIndex]}`}>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div className="color-panel__bg-switcher" onClick={() => rotateBackground()}>
BG
</div>
Expand Down

0 comments on commit 717e720

Please sign in to comment.