Skip to content

Commit b0ac9ea

Browse files
committed
Fix(NavBar, AvatarGroup): Improve keyboard accessibility for interactive controls
1 parent fb4deb8 commit b0ac9ea

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

docs/creating-components.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ Use CSS Modules for component styling:
214214
}
215215
```
216216

217+
### Accessibility
218+
219+
- Use semantic elements for interactive controls (`button`, `a`, `input`).
220+
- Avoid non-semantic elements like `div` or `span` for interactivity.
221+
- If unavoidable, add `role="button"`, `tabIndex={0}`, and keyboard handlers for Enter/Space.
222+
223+
```tsx
224+
<div
225+
role="button"
226+
tabIndex={0}
227+
onClick={handleClick}
228+
onKeyDown={e => {
229+
if (e.key === 'Enter' || e.key === ' ') handleClick();
230+
}}
231+
/>
232+
```
233+
217234
## TypeScript Best Practices
218235

219236
### Prop Types

packages/ui-components/src/Common/AvatarGroup/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
6565

6666
{avatars.length > limit && (
6767
<span
68+
role="button"
69+
tabIndex={0}
6870
onClick={handleShowMoreClick}
71+
onKeyDown={e => {
72+
if (e.key === 'Enter' || e.key === ' ') {
73+
handleShowMoreClick?.();
74+
}
75+
}}
6976
className={classNames(
7077
avatarstyles.avatar,
7178
avatarstyles[size],

packages/ui-components/src/Containers/NavBar/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ const NavBar: FC<PropsWithChildren<NavbarProps>> = ({
5454
className={style.sidebarItemTogglerLabel}
5555
htmlFor="sidebarItemToggler"
5656
role="button"
57+
tabIndex={0}
58+
onKeyDown={e => {
59+
if (e.key === 'Enter' || e.key === ' ') {
60+
const toggler = document.getElementById(
61+
'sidebarItemToggler'
62+
) as HTMLInputElement | null;
63+
toggler?.click();
64+
}
65+
}}
5766
aria-label={sidebarItemTogglerAriaLabel}
5867
>
5968
{navInteractionIcons[isMenuOpen ? 'close' : 'show']}

0 commit comments

Comments
 (0)