Design reusable accessible components
Make semantics, focus, and failure states part of the component API.
Specify behavior before props
A reusable dialog or list control needs a written interaction contract: trigger behavior, focus entry, keyboard movement, escape handling, dismissal, and what happens on errors. Visual similarity alone does not mean two controls share the same semantics. Prefer native elements before inventing keyboard behavior.
Keep state ownership clear
Decide whether the parent controls open state or the component owns it, and expose one consistent pattern. Avoid props that permit contradictory combinations such as disabled plus required action. Return focus to a sensible place after close and do not trap focus in content that has been removed.
type DialogProps = {
open: boolean;
onClose: () => void;
labelledBy: string;
children: React.ReactNode;
};
Test the contract across contexts
Exercise keyboard-only navigation, a screen reader pass, responsive layout, validation errors, and an asynchronously removed trigger. Reuse tests for behavior, not screenshots alone. A component library should reduce accessibility regressions by making the correct path the easiest path for product teams.
Check your understanding
Why is a reusable component's keyboard behavior part of its public API?
Show explanation
Consumers depend on predictable focus and activation behavior just as they depend on props and visual output.
You can read for free. Create an account to save your progress.
Next lesson: Keep several async views consistent →Try it at senior level
Specify an accessible autocomplete component API: keyboard actions, focus restoration, disabled state, error text, and async loading.
Check your work
The contract works without a mouse, exposes a stable label and status to assistive technology, and documents every failure state.
Self-guided practice. This does not record assessed mastery.
Put this lesson into practice
A related activity in this module at foundation level.
Try: Fix a loose-equality bugFurther reading
Primary references for this module. Check the current version when behavior or framework guidance may have changed.