Skip to content

Commit

Permalink
Fix accessibility issues for rest of the components
Browse files Browse the repository at this point in the history
  • Loading branch information
mbacherycz committed Jan 29, 2025
1 parent 1e7c636 commit 4da5fa0
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { getStoryContext } from '@storybook/test-runner';
import { injectAxe, checkA11y, configureAxe } from 'axe-playwright';

const config: TestRunnerConfig = {
tags:{
exclude: ['Demo']
},
async preVisit(page) {
await injectAxe(page);
},
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Dialog/DialogListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const DialogListItem = ({
}

return (
<ListItemBase {...rest} size={size} selected={selected} theme={applicableTheme}>
<ListItemBase {...rest} size={size} selected={selected} theme={applicableTheme} hidden={loading} loading={loading}>
<ListItemLink {...rest} size={size} className={styles.link}>
<div className={styles.border} data-size={size} data-seen={seen} data-loading={loading}>
<header className={styles.header} data-size={size}>
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Dialog/DialogSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type DialogSelectProps = {
export const DialogSelect = ({ checked = false, onChange, className }: DialogSelectProps) => {
return (
<label className={cx(styles.label, className)}>
<input type="checkbox" checked={checked} onChange={onChange} className={styles.input} tabIndex={-1} />
<input type="checkbox" checked={checked} onChange={onChange} className={styles.input} />
<CheckboxIcon hover={true} checked={checked} className={styles.icon} />
</label>
);
Expand Down
1 change: 1 addition & 0 deletions lib/components/Dialog/dialogSelect.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.input {
position: absolute;
opacity: 0;
display: none;
}

.icon {
Expand Down
3 changes: 2 additions & 1 deletion lib/components/Dropdown/DrawerBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export interface DrawerBaseProps {
}

export const DrawerBase = ({ placement = 'inline', open = false, className, children }: DrawerBaseProps) => {
const drawerBaseStyles = cx(styles.drawer, className, open && styles.drawerExpanded )
return (
<div
className={cx(styles.drawer, className)}
className={drawerBaseStyles}
data-placement={placement}
data-theme="default"
data-color="neutral"
Expand Down
5 changes: 3 additions & 2 deletions lib/components/Dropdown/DropdownBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ export const DropdownBase = ({
const ref = useRef<HTMLDivElement>(null);
useClickOutside(ref, onClose);

const dropdownBaseStyles = cx(styles.dropdown, className, open && styles.dropdownExpanded)

return (
<div
ref={ref}
className={cx(styles.dropdown, className)}
className={dropdownBaseStyles}
data-theme="default"
data-color="neutral"
data-shadow="md"
data-placement={placement}
data-padding={padding}
aria-expanded={open}
role="menu"
>
{children}
Expand Down
4 changes: 2 additions & 2 deletions lib/components/Dropdown/drawerBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: none;
}

.drawer[aria-expanded="true"] {
.drawerExpanded {
display: block;
width: 100%;
}
Expand All @@ -13,4 +13,4 @@
bottom: 0;
left: 0;
right: 0;
}
}
4 changes: 2 additions & 2 deletions lib/components/Dropdown/dropdownBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: none;
}

.dropdown[aria-expanded="true"] {
.dropdownExpanded {
display: block;
position: absolute;
z-index: 2;
Expand Down Expand Up @@ -30,4 +30,4 @@

.drawer .button {
border-radius: 50%;
}
}
4 changes: 2 additions & 2 deletions lib/components/Header/HeaderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export interface HeaderMenuProps {
children?: ReactNode;
}

export const HeaderMenu = ({ expanded = false, className, children }: HeaderMenuProps) => {
export const HeaderMenu = ({ className, children }: HeaderMenuProps) => {
return (
<div className={cx(styles.menu, className)} aria-expanded={expanded}>
<div className={cx(styles.menu, className)} >
{children}
</div>
);
Expand Down
5 changes: 4 additions & 1 deletion lib/components/Header/HeaderSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export interface HeaderSearchProps {
}

export const HeaderSearch = ({ expanded = false, className, children }: HeaderSearchProps) => {

const headerSearchStyles = cx(styles.search, className, expanded && styles.searchExpanded)

return (
<div className={cx(styles.search, className)} aria-expanded={expanded}>
<div className={headerSearchStyles}>
{children}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions lib/components/Header/headerSearch.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
width: 100%;
}

.search[aria-expanded="true"] {
.searchExpanded {
z-index: 2;
}

Expand All @@ -15,7 +15,7 @@
max-width: 320px;
}

.search[aria-expanded="true"] {
.searchExpanded {
max-width: 640px;
}
}
}
7 changes: 2 additions & 5 deletions lib/components/List/ListItemBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const ListItemBase = ({
const appliedShadow = theme === 'transparent' ? 'none' : shadow;

if (interactive) {
const linkClass = cx(styles.item, styles.interactive, className);
const linkClass = cx(styles.item, styles.interactive, className, selected && styles.interactiveSelected, hidden && styles.interactiveHidden);
const Component = as || 'button';

return (
Expand All @@ -75,10 +75,8 @@ export const ListItemBase = ({
}}
onClick={onClick}
tabIndex={tabIndex}
aria-hidden={hidden}
aria-disabled={disabled || loading}
aria-selected={selected}
aria-expanded={expanded}
disabled={disabled || loading}
>
{children}
</Component>
Expand All @@ -99,7 +97,6 @@ export const ListItemBase = ({
aria-hidden={hidden}
aria-disabled={disabled || loading}
aria-selected={selected}
aria-expanded={expanded}
>
{children}
</article>
Expand Down
2 changes: 0 additions & 2 deletions lib/components/List/ListItemLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const ListItemLink = ({
href,
onClick,
onKeyPress,
tabIndex,
className,
children,
}: ListItemLinkProps) => {
Expand All @@ -51,7 +50,6 @@ export const ListItemLink = ({
onKeyPress?.(e);
}}
onClick={onClick}
tabIndex={tabIndex}
aria-disabled={loading || disabled}
aria-selected={selected}
data-size={size}
Expand Down
2 changes: 1 addition & 1 deletion lib/components/List/ListItemSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ListItemSelectProps = {
export const ListItemSelect = ({ size, checked = false, onChange, className }: ListItemSelectProps) => {
return (
<label className={cx(styles.label, className)} data-size={size}>
<input type="checkbox" checked={checked} onChange={onChange} className={styles.input} tabIndex={-1} />
<input type="checkbox" checked={checked} onChange={onChange} className={styles.input} />
<CheckboxIcon hover={true} checked={checked} className={styles.icon} />
</label>
);
Expand Down
16 changes: 10 additions & 6 deletions lib/components/List/listItemBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@

/* interactive classes, active, selected, expanded */

.interactive:not([aria-selected="true"]) {
cursor: pointer;
.interactiveSelected {
outline: 2px solid var(--ds-color-border-strong);
}

.interactive:not([aria-expanded="true"]):not([data-theme="transparent"]):hover,
.interactive:not([aria-selected="true"]):not([data-theme="transparent"]):hover,
.interactive:not([aria-disabled="true"]):not([data-theme="transparent"]):hover {
outline: 2px solid var(--ds-color-border-strong);
.interactiveHidden {
display: none;
}

.interactive:not([data-theme="transparent"]):hover,
.interactive:not([data-theme="transparent"]):hover,
.interactive:not([data-theme="transparent"]):hover {
outline: 2px solid var(--ds-color-border-strong);
}
5 changes: 2 additions & 3 deletions lib/components/List/listItemSelect.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
}

.input {
position: absolute;
opacity: 0;
display: none;
}

.icon {
Expand Down Expand Up @@ -81,4 +80,4 @@
.label[data-size="xl"] .icon {
width: 24px;
height: 24px;
}
}
9 changes: 4 additions & 5 deletions lib/components/Menu/MenuBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ export interface MenuListItemProps {
export const MenuBase = ({ as = 'nav', color, theme, className, children }: MenuBaseProps) => {
const Component = as;
return (
<Component className={cx(styles.menu, className)} data-color={color} data-theme={theme} role="menu">
<Component className={cx(styles.menu, className)} data-color={color} data-theme={theme}>
{children}
</Component>
);
};

export const MenuList = ({ as = 'ul', role = 'group', expanded, className, children }: MenuListProps) => {
export const MenuList = ({ as = 'ul', role = 'group', className, children }: MenuListProps) => {
const Component = as;
return (
<Component className={cx(styles.list, className)} role={role} aria-expanded={expanded}>
<Component className={cx(styles.list, className)} role={role}>
{children}
</Component>
);
Expand All @@ -53,13 +53,12 @@ export const MenuList = ({ as = 'ul', role = 'group', expanded, className, child
export const MenuListItem = ({
as = 'li',
role = 'presentation',
expanded,
className,
children,
}: MenuListItemProps) => {
const Component = as;
return (
<Component className={cx(styles.item, className)} role={role} aria-expanded={expanded}>
<Component className={cx(styles.item, className)} role={role}>
{children}
</Component>
);
Expand Down
7 changes: 0 additions & 7 deletions lib/components/Menu/MenuItemBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export const MenuItemBase = ({
tabIndex = 0,
hidden,
disabled = false,
active = false,
selected = false,
expanded = false,
linkIcon,
linkText,
badge,
Expand All @@ -52,17 +49,13 @@ export const MenuItemBase = ({

return (
<Component
role="menuitem"
tabIndex={disabled ? '-1' : (tabIndex ?? 0)}
className={cx(styles.item, className)}
data-size={size}
data-color={color}
data-theme={theme}
data-active={active}
aria-hidden={hidden}
aria-expanded={expanded}
aria-disabled={disabled}
aria-selected={selected}
href={href}
onKeyPress={(e: KeyboardEvent) => {
e.key === 'Enter' && onClick?.();
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Menu/MenuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const MenuItems = ({
const { expanded } = itemProps;
const nextItem = group?.items[index + 1];
return (
<MenuListItem role="presentation" expanded={expanded} key={index}>
<MenuListItem expanded={expanded} key={index}>
<MenuItem
{...itemProps}
size={itemProps?.size || groupProps?.defaultItemSize || defaultItemSize}
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Menu/menuBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

.item[role="separator"] {
border-top: 1px solid var(--ds-color-border-subtle);
}
}
8 changes: 4 additions & 4 deletions lib/components/Menu/menuSearch.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
position: absolute;
top: 0;
right: 0;
margin: 10px;
margin: 8px;
border-radius: 100%;
width: 1.25rem;
height: 1.25rem;
}
width: 1.5rem;
height: 1.5rem;
}
3 changes: 1 addition & 2 deletions lib/components/Searchbar/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const SearchField = ({
};

return (
<div className={cx(styles.field, className)} aria-expanded={expanded}>
<div className={cx(styles.field, className)}>
<input
ref={ref}
onFocus={onFocus}
Expand All @@ -62,7 +62,6 @@ export const SearchField = ({
aria-haspopup
autoComplete="off"
aria-autocomplete="list"
aria-expanded={expanded}
tabIndex={tabIndex ?? 0}
/>
<Icon name="magnifying-glass" className={styles.icon} />
Expand Down
4 changes: 2 additions & 2 deletions lib/components/Searchbar/SearchbarBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export interface SearchbarBaseProps {
}

export const SearchbarBase = ({ className, children, expanded = false, autocomplete = false }: SearchbarBaseProps) => {
const searchBaseStyles = cx(styles.searchbar, className, expanded && styles.searchbarExpanded)
return (
<div
className={cx(styles.searchbar, className)}
aria-expanded={expanded}
className={searchBaseStyles}
data-autocomplete={autocomplete}
data-color="neutral"
>
Expand Down
4 changes: 2 additions & 2 deletions lib/components/Searchbar/searchbarBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
display: none;
}

.searchbar[aria-expanded="true"] nav {
.searchbarExpanded nav {
position: absolute;
display: block;
border-top-left-radius: 0;
border-top-right-radius: 0;
margin-top: -2px;
}
}
8 changes: 7 additions & 1 deletion lib/components/Skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ interface SkeletonProps {
export const Skeleton = ({ loading = false, size, variant = 'text', className, children }: SkeletonProps) => {
if (loading) {
return (
<span className={cx(styles.skelaton, className)} data-size={size} data-loading={loading} data-variant={variant}>
<span
className={cx(styles.skelaton, className)}
data-size={size}
data-loading={loading}
data-variant={variant}
aria-hidden="true"
>
{children}
</span>
);
Expand Down
Loading

0 comments on commit 4da5fa0

Please sign in to comment.