Accessibility Debug and Code Review: 6 Common ARIA, Keyboard, and Focus Bugs
In front-end code-review and debugging interviews for developers with 0–5 years of experience, accessibility bugs frequently separate candidates who build purely visual interfaces from engineers who build production-ready web applications. Interviewers evaluate whether you spot missing keyboard handlers, broken ARIA relationships, silent live regions, and focus-visibility regressions before code ships.
This guide presents six realistic React and HTML snippets containing common accessibility bugs, along with the symptom, root cause, fixed implementation, and a concise spoken explanation.
Question Index
| # | Bug Focus | Core Concept | Difficulty |
|---|---|---|---|
| 1 | Clickable <div> with role="button" | Native semantics vs. keyboard activation | Junior-Mid |
| 2 | Icon-only button & decorative SVG | Accessible names & aria-hidden | Junior |
| 3 | Placeholder-only form field | <label> association & aria-describedby | Junior-Mid |
| 4 | Custom tablist without roving tabIndex | Arrow-key navigation & ARIA tab roles | Mid-Senior |
| 5 | Dynamically mounted aria-live toast | Live region DOM lifecycle | Mid-Senior |
| 6 | outline: none & focusable aria-hidden | :focus-visible & accessibility tree conflicts | Mid |
Q1. Why does this custom <div> button fail keyboard users, and how would you fix it?
Level: Junior-Mid
What the interviewer is checking: Understanding that role="button" only changes the accessibility tree announcement and does not add focusability or Enter/Space activation.
Short answer to say out loud
"Adding role="button" to a <div> tells screen readers it is a button, but it does not make the element focusable or respond to Enter and Space keys. The cleanest fix is replacing the <div> with a native <button type="button">, which gives us keyboard activation, focusability, and form safety for free."
Detailed explanation
- Symptom: Keyboard-only users cannot Tab to the card action, and pressing
EnterorSpacedoes nothing. - Root cause: Unlike
<button>, a<div>has no implicittabIndexand no built-in keydown-to-click synthesis.
// Buggy snippet
function SaveAction({ onSave }: { onSave: () => void }) {
return (
<div role="button" className="save-pill" onClick={onSave}>
Save Draft
</div>
);
}
Example
// Fixed: prefer native <button> over role="button"
function SaveAction({ onSave }: { onSave: () => void }) {
return (
<button type="button" className="save-pill" onClick={onSave}>
Save Draft
</button>
);
}
Common mistakes
- Adding
tabIndex={0}withoutonKeyDownforEnterandSpace. - Using
<button>inside a<form>withouttype="button", which defaults totype="submit".
Likely follow-up questions
- "If design constraints forced you to use a non-button element, what exact keyboard behavior must
onKeyDownimplement forSpacevs.Enter?" - "What happens if you place a
<button>inside another<button>?"
Q2. What is wrong with this icon-only close button for screen-reader users?
Level: Junior
What the interviewer is checking: Knowing how accessible names are computed and how decorative SVGs should be hidden from assistive technology.
Short answer to say out loud
"This <button> has no text content or aria-label, so a screen reader announces it as an unlabeled 'button'—or reads raw SVG markup. Adding a descriptive aria-label on the button and aria-hidden="true" on the decorative <svg> fixes both issues."
Detailed explanation
- Symptom: Screen readers announce "button" with no action description, and VoiceOver/NVDA may traverse internal
<path>nodes. - Root cause: An icon-only button has an empty accessible name unless labeled via
aria-label, visually hidden text, or<svg><title>.
// Buggy snippet
function CloseButton({ onClose }: { onClose: () => void }) {
return (
<button type="button" onClick={onClose}>
<svg viewBox="0 0 24 24" width="20" height="20">
<path d="M6 6l12 12M18 6L6 18" stroke="currentColor" />
</svg>
</button>
);
}
Example
// Fixed: provide aria-label on button and hide decorative SVG
function CloseButton({ onClose }: { onClose: () => void }) {
return (
<button type="button" aria-label="Close notification" onClick={onClose}>
<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false">
<path d="M6 6l12 12M18 6L6 18" stroke="currentColor" />
</svg>
</button>
);
}
Common mistakes
- Putting
aria-labelon the<svg>instead of the<button>, leaving the button itself unnamed. - Relying on the
titleattribute, which is inconsistently exposed to touch and keyboard users.
Likely follow-up questions
- "When is visually hidden text (
sr-only) preferable toaria-label?" - "Why is
focusable="false"sometimes added to inline SVGs?"
Q3. Why does this email input fail accessibility audits and screen-reader form navigation?
Level: Junior-Mid
What the interviewer is checking: Understanding explicit <label> association, why placeholder is not a label, and programmatic error association with aria-invalid and aria-describedby.
Short answer to say out loud
"Using placeholder as the only label disappears as soon as the user types and does not give the <input> a reliable accessible name. Also, the error message is visually below the input but not linked via aria-describedby or flagged with aria-invalid."
Detailed explanation
- Symptom: Clicking the field description does not focus the input, screen readers lose context once text is entered, and validation errors are not announced when focusing the invalid input.
- Root cause: Missing
<label htmlFor={id}>and missingaria-invalid/aria-describedbybindings.
// Buggy snippet
function EmailField({ value, error, onChange }: { value: string; error?: string; onChange: (v: string) => void }) {
return (
<div>
<input type="email" placeholder="Work email" value={value} onChange={(e) => onChange(e.target.value)} />
{error && <p className="error">{error}</p>}
</div>
);
}
Example
// Fixed: explicit label + aria-invalid + aria-describedby
function EmailField({ value, error, onChange }: { value: string; error?: string; onChange: (v: string) => void }) {
const inputId = 'work-email';
const errorId = 'work-email-error';
return (
<div>
<label htmlFor={inputId}>Work email</label>
<input
id={inputId}
type="email"
value={value}
aria-invalid={Boolean(error)}
aria-describedby={error ? errorId : undefined}
onChange={(e) => onChange(e.target.value)}
/>
{error && (
<p id={errorId} role="alert" className="error">
{error}
</p>
)}
</div>
);
}
Common mistakes
- Using duplicate hardcoded
idvalues across multiple instances of a reusable input component (use React'suseId()in production). - Relying on red border color alone without text or
aria-invalid.
Likely follow-up questions
- "How does React's
useId()solve ID collisions in reusable form components?" - "When should an error message use
role="alert"vs.aria-describedbyalone?"
Q4. What accessibility bugs exist in this custom Tabs component?
Level: Mid-Senior
What the interviewer is checking: Knowledge of the WAI-ARIA Tabs pattern: role="tablist", role="tab", role="tabpanel", aria-selected, aria-controls, and roving tabIndex with arrow-key navigation.
Short answer to say out loud
"This tab bar has no ARIA tab semantics (tablist, tab, tabpanel), does not expose aria-selected, and forces keyboard users to Tab through every tab instead of using Left/Right arrow keys with roving tabIndex."
Detailed explanation
- Symptom: Screen readers announce plain buttons with no selected state, and keyboard users cannot switch tabs with ArrowLeft/ArrowRight.
- Root cause: Missing ARIA roles/attributes (
aria-selected,aria-controls,aria-labelledby) and missing rovingtabIndex(0on the active tab,-1on inactive tabs).
// Buggy snippet
function Tabs({ items }: { items: Array<{ id: string; label: string; body: string }> }) {
const [active, setActive] = useState(items[0].id);
const current = items.find((i) => i.id === active)!;
return (
<div>
<div>
{items.map((item) => (
<button key={item.id} type="button" onClick={() => setActive(item.id)}>
{item.label}
</button>
))}
</div>
<div>{current.body}</div>
</div>
);
}
Example
// Fixed: WAI-ARIA Tabs roles + roving tabIndex + arrow key navigation
function Tabs({ items }: { items: Array<{ id: string; label: string; body: string }> }) {
const [activeIndex, setActiveIndex] = useState(0);
const tabRefs = useRef<Array<HTMLButtonElement | null>>([]);
const handleKeyDown = (e: React.KeyboardEvent, index: number) => {
let next = index;
if (e.key === 'ArrowRight') next = (index + 1) % items.length;
else if (e.key === 'ArrowLeft') next = (index - 1 + items.length) % items.length;
else if (e.key === 'Home') next = 0;
else if (e.key === 'End') next = items.length - 1;
else return;
e.preventDefault();
setActiveIndex(next);
tabRefs.current[next]?.focus();
};
const current = items[activeIndex];
return (
<div>
<div role="tablist" aria-label="Account sections">
{items.map((item, idx) => {
const selected = idx === activeIndex;
return (
<button
key={item.id}
ref={(el) => { tabRefs.current[idx] = el; }}
id={`tab-${item.id}`}
role="tab"
type="button"
aria-selected={selected}
aria-controls={`panel-${item.id}`}
tabIndex={selected ? 0 : -1}
onClick={() => setActiveIndex(idx)}
onKeyDown={(e) => handleKeyDown(e, idx)}
>
{item.label}
</button>
);
})}
</div>
<div id={`panel-${current.id}`} role="tabpanel" aria-labelledby={`tab-${current.id}`} tabIndex={0}>
{current.body}
</div>
</div>
);
}
Common mistakes
- Setting
tabIndex={0}on all tabs instead of rovingtabIndex(0for active,-1for inactive). - Forgetting
e.preventDefault()on arrow keys orHome/End, which causes the page to scroll.
Likely follow-up questions
- "What is the difference between automatic tab activation (focus changes panel) and manual activation (
Enter/Spaceactivates panel)?" - "When would you use
aria-activedescendantinstead of rovingtabIndex?"
Q5. Why does this aria-live toast notification often fail to announce in screen readers?
Level: Mid-Senior
What the interviewer is checking: Understanding that an aria-live container must already exist in the DOM before its text content changes.
Short answer to say out loud
"Screen readers register live regions when they mount. Conditionally mounting the aria-live element at the same instant as its message means the assistive technology often misses the initial announcement. Keep the live region mounted permanently and update its inner text when a toast triggers."
Detailed explanation
- Symptom: The toast appears visually on screen, but NVDA, JAWS, or VoiceOver intermittently or completely fails to speak the message.
- Root cause: Conditional rendering (
{message && <div aria-live="polite">{message}</div>}) inserts the live region and text in the same DOM mutation.
// Buggy snippet
function ToastBanner({ message }: { message: string | null }) {
if (!message) return null;
return (
<div role="status" aria-live="polite" className="toast">
{message}
</div>
);
}
Example
// Fixed: keep the live region mounted and inject message text into it
function ToastBanner({ message }: { message: string | null }) {
return (
<div role="status" aria-live="polite" aria-atomic="true" className={message ? 'toast visible' : 'sr-only'}>
{message ?? ''}
</div>
);
}
Common mistakes
- Using
aria-live="assertive"for routine success messages, which interrupts whatever the user is currently reading. - Setting
display: noneon the live region when empty instead of keeping it rendered.
Likely follow-up questions
- "What does
aria-atomic="true"control inside a live region?" - "When should you use
role="alert"(assertive) vs.role="status"(polite)?"
Q6. What two focus and accessibility-tree bugs are hidden in this CSS + JSX snippet?
Level: Mid
What the interviewer is checking: Understanding :focus-visible vs. removing focus outlines globally, and why aria-hidden="true" must never wrap a focusable element.
Short answer to say out loud
"First, outline: none without a replacement indicator strips keyboard users of visible focus; we should style :focus-visible instead. Second, putting aria-hidden="true" on a focusable <button> hides it from screen readers while still allowing keyboard focus to land on it—creating a silent 'ghost' focus stop."
Detailed explanation
- Symptom: Keyboard users cannot see where focus is on the page, and screen-reader users tab onto an invisible, silent stop.
- Root cause: Global
outline: nonebreaks WCAG Focus Visible, andaria-hidden="true"on focusable elements violates the fourth rule of ARIA.
/* Buggy CSS */
button:focus {
outline: none;
}
// Buggy JSX
<button type="button" aria-hidden="true" onClick={onSkip}>
Skip animation
</button>
Example
/* Fixed CSS: preserve keyboard focus visibility without cluttering mouse clicks */
button:focus {
outline: none;
}
button:focus-visible {
outline: 2px solid #2563eb;
outline-offset: 2px;
}
// Fixed JSX: if an element should be non-interactive and hidden, remove it from tab order or omit it
<button type="button" onClick={onSkip}>
Skip animation
</button>
Common mistakes
- Using
aria-hidden="true"to hide off-screen drawers instead of the HTMLinertattribute ordisplay: none. - Applying
outline: noneon*in a CSS reset without a:focus-visiblefallback.
Likely follow-up questions
- "How does the HTML
inertattribute solve background focus trapping better thanaria-hidden="true"?" - "How does
:focus-visiblediffer from:focusin browsers?"
Preparation Checklist
- Prefer native HTML: Always reach for
<button>,<a href>, and<label>before adding ARIA roles. - Test with keyboard only: Tab through every interactive flow (
Tab,Shift+Tab,Enter,Space,Escape, Arrow keys). - Pre-mount live regions: Keep
aria-live="polite"containers in the DOM before updating status messages. - Never hide focusable elements: Audit for
aria-hidden="true"on any element withtabIndex >= 0or native focusability. - Use
:focus-visible: Preserve clear focus rings for keyboard navigation without bothering pointer users.
Conclusion
Debugging accessibility issues during code review shows interviewers that you treat semantic HTML, keyboard operability, and assistive technology behavior as core engineering requirements. By catching missing labels, broken roving tabIndex, unmounted live regions, and aria-hidden focus traps early, you build interfaces that work reliably for every user.