npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@simplero/react-windowed-select

v3.1.6

Published

[![Travis][build-badge]][build] [![npm package][npm-badge]][npm] [![Coveralls][coveralls-badge]][coveralls] [![Storybook][storybook-badge]][storybook]

Downloads

1

Readme

react-windowed-select

Travis npm package Coveralls Storybook

An integration of react-window with react-select to efficiently render large lists.

Installation and Usage

The easiest way to use react-windowed-select is to install it from npm:

npm install react-windowed-select

Then use it in your app:

import React from "react";
import WindowedSelect from "react-windowed-select";

const options = [];

for (let i = 0; i < 10000; i += 1) {
  options.push({
    label: `Option ${i}`,
    value: i
  });
}

function App () {
  return <WindowedSelect options={options} />;
}

Edit react-windowed-select

For more examples, check out the Storybook.

Props

react-windowed-select is just a wrapper around react-select. All props passed to the WindowedSelect component are forwarded to the default exported Select component from react-select.

windowThreshold | default = 100

The number of options beyond which the menu will be windowed.

Named Exports

All of the named exports from react-select are re-exported from react-windowed-select for easy access to features that allow you to customize your Select component.

import { components, createFilter } from 'react-windowed-select';
import React from "react";

const options = [
  { value: 1, label: 'Foo' },
  { value: 2, label: 'Bar '},
];

const customFilter = createFilter({ ignoreAccents: false });
const customComponents = {
  ClearIndicator: (props) => <components.ClearIndicator {...props}>clear</components.ClearIndicator>
};

function App () {
  return (
    <WindowedSelect
       components={customComponents}
       isClearable={true}
       filterOption={customFilter}
       options={options}
     />
   );
}

Edit react-windowed-select custom filter and component

WindowedMenuList

By default, react-windowed-select wraps the standard Select component from react-select. If you want to add windowing to the Async or Creatable Select components from react-select, use the WindowedMenuList:

import { WindowedMenuList } from 'react-windowed-select';
import CreatableSelect from 'react-select/creatable';

function App () {
  return (
    <CreatableSelect
      components={{ MenuList: WindowedMenuList }}
      // ...other props
    />
  );
}

Custom Styles

You can still use the styles API from react-select to customize how your Select component looks. The height property of the Option, GroupHeading, NoOptionsMessage and/or LoadingMessage components is used to determine the total height of the windowed menu and the following defaults are provided:

|Component |Default Height| |------------------|--------------| |Option |35px | |GroupHeading |25px | |NoOptionsMessage|35px | |LoadingMessage |35px |

To override these values, use the styles prop like you would with a regular react-select component.

<WindowedSelect
  options={options}
  styles={{
    option: (base) => ({
      ...base,
      height: 60, // must be type number
      padding: '20px 12px',
    }),
  }}
/>

Grouped Options

Grouped options are not fully supported. In order to ensure proper scrolling and focus behavior, options nested inside the Group component are flattened. This changes the component structure within MenuList in the following way:

MenuList  
│
└───Group
│   │
|   └───GroupHeading
|
└───Option 1
|
└───Option 2