Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions docs/creating-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ Use CSS Modules for component styling:
}
```

### Accessibility

- Use semantic elements for interactive controls (`button`, `a`, `input`).
- Avoid non-semantic elements like `div` or `span` for interactivity.
- If unavoidable, add `role="button"`, `tabIndex={0}`, and keyboard handlers for Enter/Space.

```tsx
<div
role="button"
tabIndex={0}
onClick={handleClick}
onKeyDown={e => {
if (e.key === 'Enter' || e.key === ' ') handleClick();
}}
/>
```

## TypeScript Best Practices

### Prop Types
Expand Down
7 changes: 7 additions & 0 deletions packages/ui-components/src/Common/AvatarGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ const AvatarGroup: FC<AvatarGroupProps> = ({

{avatars.length > limit && (
<span
role="button"
Copy link
Member

Choose a reason for hiding this comment

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

You can already navigate through avatars with tab without any of this. -1 to the change.

tabIndex={0}
onClick={handleShowMoreClick}
onKeyDown={e => {
if (e.key === 'Enter' || e.key === ' ') {
handleShowMoreClick?.();
}
}}
className={classNames(
avatarstyles.avatar,
avatarstyles[size],
Expand Down
9 changes: 9 additions & 0 deletions packages/ui-components/src/Containers/NavBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ const NavBar: FC<PropsWithChildren<NavbarProps>> = ({
className={style.sidebarItemTogglerLabel}
htmlFor="sidebarItemToggler"
role="button"
tabIndex={0}
onKeyDown={e => {
if (e.key === 'Enter' || e.key === ' ') {
Copy link
Member

Choose a reason for hiding this comment

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

I'm -1 of this change. I'm unsure of what you're trying to achieve here, but this menu is only visible on mobile screens, which very often are touch-only. Screen readers should already be accessible to this with aria-label, there's no need for an onKeyDown here.

const toggler = document.getElementById(
'sidebarItemToggler'
) as HTMLInputElement | null;
toggler?.click();
}
}}
aria-label={sidebarItemTogglerAriaLabel}
>
{navInteractionIcons[isMenuOpen ? 'close' : 'show']}
Expand Down
Loading