Course contentsShow
← Web Development
Lesson 2105 of 2,98238. JavaScript Performance in the BrowserFree lesson

Accessibility Considerations for Virtual Lists

Maintaining keyboard navigation, screen reader announcements, and focus management in virtualized content.

Accessibility Considerations for Virtual Lists

You'll learn how to keep virtualized lists usable for keyboard users and screen reader users, even though most of the content isn't actually in the DOM.

The Challenge

Virtualization creates an inherent tension with accessibility. When you only render 10 visible items out of 1,000, keyboard navigation and screen readers lose their usual context. Pressing down-arrow expects the next DOM element, but it doesn't exist yet. Screen readers announce "list of 10 items" when there are actually 1,000. Focus disappears when items scroll out of view and get unmounted.

Think of it like a physical library catalog: You're looking at one drawer of cards, but the screen reader thinks that drawer is the entire catalog. Your job is to make the invisible drawers "count" anyway.

Core Accessibility Requirements

Keyboard Navigation: Ensure arrow keys work seamlessly. When a user presses down-arrow, intercept it, update your visible range to include the next item, and programmatically move focus to the newly-rendered element. Don't rely on native DOM traversal alone.

ARIA Attributes: Use role="list" and role="listitem" explicitly. Add aria-setsize (total item count) and aria-posinset (current item position) to each rendered item so screen readers announce "item 347 of 1,000" accurately.

Focus Management: When scrolling causes the focused item to unmount, save its index. When it re-renders, restore focus immediately. Use useRef or similar to track focus state across render cycles.

Screen Reader Announcements: Consider aria-live regions to announce when new content loads during scrolling, especially for infinite scroll patterns.

Landmark Roles: Wrap your virtual list in proper landmarks (<nav> for navigation lists, <main> for content) so users can skip to/from it efficiently.

Key Takeaway: Virtual lists require manual accessibility implementation—keyboard navigation, ARIA attributes for accurate counts/positions, and careful focus management—because the DOM doesn't represent the full data structure.