Skip to content

Commit cbe2233

Browse files
committed
Add menuComponent option for custom Menu rendering.
Also added new example that implements react-virtualized to render a large list of 300 items, with virtualized scrolling for perf.
1 parent 18758f7 commit cbe2233

File tree

6 files changed

+1891
-13
lines changed

6 files changed

+1891
-13
lines changed

examples/src/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Select from 'react-select';
66

77
import Contributors from './components/Contributors';
88
import CustomComponents from './components/CustomComponents';
9+
import CustomMenuComponent from './components/CustomMenuComponent';
910
import CustomRender from './components/CustomRender';
1011
import Multiselect from './components/Multiselect';
1112
import NumericSelect from './components/NumericSelect';
@@ -19,6 +20,7 @@ ReactDOM.render(
1920
<NumericSelect label="Numeric Values" />
2021
<CustomRender label="Custom Render Methods"/>
2122
<CustomComponents label="Custom Placeholder, Option and Value Components" />
23+
<CustomMenuComponent label="Custom Menu Component" />
2224
{/*
2325
<SelectedValuesField label="Option Creation (tags mode)" options={FLAVOURS} allowCreate hint="Enter a value that's NOT in the list, then hit return" />
2426
*/}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
import Select from 'react-select';
3+
import { VirtualScroll } from 'react-virtualized';
4+
5+
const PEOPLE = require('../data/large');
6+
7+
const InfiniteList = React.createClass({
8+
render () {
9+
let { children, style, ...props } = this.props;
10+
11+
return (
12+
<VirtualScroll
13+
height={200}
14+
{...props}
15+
rowRenderer={this.renderRow}
16+
rowsCount={children.length}
17+
rowHeight={35}
18+
children={children /* Pass this so the list re-renders when children are hovered/change */}
19+
/>
20+
);
21+
},
22+
23+
renderRow(index) {
24+
let { children } = this.props;
25+
return children[index];
26+
}
27+
});
28+
29+
const CustomMenuComponent = React.createClass({
30+
propTypes: {
31+
hint: React.PropTypes.string,
32+
label: React.PropTypes.string,
33+
},
34+
getInitialState () {
35+
return {};
36+
},
37+
setValue (value) {
38+
this.setState({ value });
39+
},
40+
render () {
41+
return (
42+
<div className="section">
43+
<h3 className="section-heading">{this.props.label}</h3>
44+
<Select
45+
onChange={this.setValue}
46+
menuComponent={InfiniteList}
47+
placeholder={`Select one of these ${PEOPLE.length} people...`}
48+
options={PEOPLE}
49+
value={this.state.value}
50+
labelKey="name"
51+
valueKey="id"
52+
/>
53+
<div className="hint">
54+
This example implements a custom Menu components to render a an infinite list using a react-list.
55+
</div>
56+
</div>
57+
);
58+
}
59+
});
60+
61+
module.exports = CustomMenuComponent;

0 commit comments

Comments
 (0)