Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve a11y on some components #1045

Merged
merged 19 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/DropdownMenu/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const DropdownMenu = <T,>({

return (
<DropdownMenuContext.Provider value={contextValue}>
{/* It is used to handle clicks on the switcher control */}
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div
ref={anchorRef}
Expand Down
7 changes: 4 additions & 3 deletions src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,24 @@ 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}
ref={ref as React.Ref<HTMLAnchorElement>}
href={href}
target={target}
rel={relProp}
/>
>
{commonProps.children}
</a>
);
} else {
return (
<span
{...(extraProps as React.HTMLAttributes<HTMLSpanElement>)}
{...commonProps}
ref={ref as React.Ref<HTMLSpanElement>}
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
role="link"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it is true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argeed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think we should remove this behaviour in the next major (#600)

tabIndex={0}
/>
);
Expand Down
12 changes: 8 additions & 4 deletions src/components/Popup/__stories__/Popup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Meta, StoryFn} from '@storybook/react';
import {useVirtualElementRef} from '../../../hooks';
import {Button} from '../../Button';
import {TextInput} from '../../controls';
import {useUniqId} from '../../utils/useUniqId';
import {Popup} from '../Popup';
import type {PopupPlacement, PopupProps} from '../Popup';

Expand Down Expand Up @@ -93,12 +94,15 @@ export const Position: StoryFn<PopupProps> = (args) => {
const [left, setLeft] = React.useState(100);
const [top, setTop] = React.useState(100);
const anchorRef = useVirtualElementRef({rect: {top, left}});

const id = useUniqId();

return (
<div>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label style={{display: 'flex', alignItems: 'center'}}>
<label htmlFor={id + '1'} style={{display: 'flex', alignItems: 'center'}}>
x:
<TextInput
id={id + '1'}
value={String(left)}
onUpdate={(value) => {
setLeft(Number(value));
Expand All @@ -108,10 +112,10 @@ export const Position: StoryFn<PopupProps> = (args) => {
style={{width: 100}}
/>
</label>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label style={{display: 'flex', alignItems: 'center'}}>
<label htmlFor={id + '2'} style={{display: 'flex', alignItems: 'center'}}>
y:
<TextInput
id={id + '2'}
value={String(top)}
onUpdate={(value) => {
setTop(Number(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {

return (
<div className={b(null, className)}>
{/* It is used to handle clicks on the switcher control */}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should not work this way

we should pass handler via some context i guess to easily pass it to rendered component

{/* 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 || (
Expand Down
10 changes: 10 additions & 0 deletions src/components/UserAvatar/UserAvatar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ $block: '.#{variables.$ns}user-avatar';
background-position: center;
background-size: cover;

outline: none;

&:focus {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably have SCSS mixin for it

box-shadow: 0 0 0 2px var(--g-color-line-focus);
}

&:focus:not(:focus-visible) {
box-shadow: none;
}

&_size {
&_xs {
width: 24px;
Expand Down
14 changes: 12 additions & 2 deletions src/components/UserAvatar/UserAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import {block} from '../utils/cn';
import {useActionHandlers} from '../utils/useActionHandlers';

import {SIZES} from './constants';
import type {UserAvatarSize} from './types';
Expand Down Expand Up @@ -34,9 +35,18 @@ export const UserAvatar = React.forwardRef<HTMLDivElement, UserAvatarProps>(
setIsErrored(false);
}, [imgUrl]);

const {onKeyDown} = useActionHandlers(onClick);

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div className={b({size}, className)} title={title} onClick={onClick} ref={ref}>
<div
role="button"
tabIndex={0}
onKeyDown={onKeyDown}
className={b({size}, className)}
title={title}
onClick={onClick}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onClick supposed to be removed from this component

ref={ref}
>
<img
className={b('figure')}
width={SIZES[size]}
Expand Down
1 change: 1 addition & 0 deletions src/components/controls/TextInput/AdditionalContent.tsx
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 (
// It is used to focus the control input if non-interaction element is provided.
// 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}
Expand Down
Loading