Skip navigation
Why does React Aria have its own Virtualizer? Why not use an existing library? Accessibility.
0:00 / 0:21

Why does React Aria have its own Virtualizer? Why not use an existing library? Accessibility.

Devon Govett

@devongovett43K followers

Visit on X
224 likesDownloadOriginal post

20,420 views

Why does React Aria have its own Virtualizer? Why not use an existing library? Accessibility. If you combine a virtualizer with most component libraries, you might notice that keyboard navigation breaks. That's because scrolling the focused element out of view removes it from the DOM. Then when you press the arrow keys, nothing happens because the list has lost focus. React Aria's Virtualizer is deeply integrated with our components, so we can automatically persist the focused item in the DOM even when it scrolls out of view.

10 Comments

Comments from the original post on X (Twitter)

  • Devon Govett's profile picture

    @devongovett

    We also automatically add ARIA attributes like aria-setsize and aria-posinset to items so that screen readers know where they are in the entire list, rather than only what's in the DOM. Hierarchy is also important. If you have a list with sections, keeping the headers in the DOM when items within a section are visible preserves the ability for screen readers to announce properly. We also integrate with React Aria's drag and drop, table column resizing, etc.

    17 likes

  • Devon Govett's profile picture

    @devongovett

    But, like all of React Aria Components, there's always a lower level API if you want to do something custom. Virtualizer is built on our CollectionRenderer API, which lets you customize how collection components are rendered to the DOM. So you could use this to integrate with a different virtualizer library. Just keep those accessibility features in mind! 🙂

    14 likes

  • Alex Vipond's profile picture

    @AlPalVipond

    Persisting the focused element is genius 🧠

    1 like

  • Andy Hook's profile picture

    @Andy_Hook

    Great work Devon + team

    1 like

  • Gijs Rogé's profile picture

    @GijsRoge

    Does that mean ctrl+f keeps working?

  • Devon Govett's profile picture

    @devongovett

    I don't believe there is a way to do that without rendering all items to the DOM, which defeats the performance benefits of virtualizing. We'd need a new browser API I think.

    4 likes

  • Unbound's profile picture

    @unbound_dev

    Have you considered improving accessibility in an existing open source project? Is it really harder than making the whole library from scratch?

  • Devon Govett's profile picture

    @devongovett

    Actually, we've been using this implementation in production for almost 10 years now! It's been open source for almost 5, as part of React Spectrum. Really, this is just integrating it with React Aria Components and adding docs.

    3 likes

  • Saurabh 🔅🦀's profile picture

    @Saurabh_kakran

    Does this work well with a large draggable list tree? Most of them do not work with a draggable context.

  • Devon Govett's profile picture

    @devongovett

    Yes drag and drop is integrated.

    1 like