Skip to content

Repository files navigation

react-windowed-select

Travisnpm packageCoverallsStorybook

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:

importReactfrom"react";importWindowedSelectfrom"react-windowed-select";constoptions=[];for(leti=0;i<10000;i+=1){options.push({label: `Option ${i}`,value: i});}functionApp(){return<WindowedSelectoptions={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';importReactfrom"react";constoptions=[{value: 1,label: 'Foo'},{value: 2,label: 'Bar '},];constcustomFilter=createFilter({ignoreAccents: false});constcustomComponents={ClearIndicator: (props)=><components.ClearIndicator{...props}>clear</components.ClearIndicator>};functionApp(){return(<WindowedSelectcomponents={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';importCreatableSelectfrom'react-select/creatable';functionApp(){return(<CreatableSelectcomponents={{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:

ComponentDefault Height
Option35px
GroupHeading25px
NoOptionsMessage35px
LoadingMessage35px

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

<WindowedSelectoptions={options}styles={{option: (base)=>({
...base,height: 60,// must be type numberpadding: '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

About

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

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages