Coder Social home page Coder Social logo

react-simple-vlist's Introduction

react-simple-vlist

MIT Licensed

A very simple virtualized list. This component only attempts to solve the problems of virtualized, vertical scrolling, in a very simple way. Nothing else.

Important

By contributing to this repository, you're agreeing to follow a code of conduct. Thank you.

Basic Usage

Below shows the most naive usage of the component.

import React from 'react';
import VList from 'react-simple-vlist';

function BasicUsage() {
  /**
   * A generated list of items.
   */
  const items = Array.from({ length: 100000 }, (_, i) => ({
    id: i,
    name: `Item ${i}`,
    data: Math.round(Math.random() * 100),
  }));

  return (
    <VList items={items} itemHeight={50} height={200}>
      {(item, itemIndex) => (
        <>
          {item.name}: {item.data}
        </>
      )}
    </VList>
  );
}

a11y

Because the aim of this component is to handle only what is necessary to virtualize a list vertically in terms of DOM-manipulation, this component does nothing on its own to setup ARIA attributes or roles. However, it does expose two properties that allow custom properties to be set on the scrollable container and the individual item containers (for visible items). Those properties are containerProps and itemProps, respectively.

For example, dealing with a virtualized list of articles you may do the following:

<VList
  items={listOfArticles}
  itemHeight={150}
  height={800}
  containerProps={{
    role: 'feed',
  }}
>
  {(art, i) => (
    <article aria-posinset={i} aria-setsize={listOfArticles.length}>
      <h2>{art.title}</h2>
      <p>{art.summary}</p>
    </article>
  )}
</VList>

Or perhaps you want just a simple virtualized list of items:

<VList
  items={allTheNamesEver}
  itemHeight={30}
  height={800}
  containerProps={{
    role: 'list',
  }}
  itemProps={{
    role: 'listitem',
  }}
>
  {(name, i) => <>{name}</>}
</VList>

(NOTE: To any a11y experts, I'd love help improving these examples)

react-simple-vlist's People

Contributors

benlesh avatar dependabot[bot] avatar skrivle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.