Skip to content

Commit

Permalink
Updated README. Added :labelKey to Select
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Mar 31, 2016
1 parent 03b3f00 commit 071ae88
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ You can also completely replace the method used to filter either a single option

For multi-select inputs, when providing a custom `filterOptions` method, remember to exclude current values from the returned array of options.

#### Effeciently rendering large lists with windowing

The `renderMenu` property can be used to override the default drop-down list of options. This should be done when the list is large (hundreds or thousands of items) for faster rendering. The custom `renderMenu` property accepts the following named parameters:

```js
focusedOption, // The currently focused option; should be visible in the menu by default.
focusOption, // Callback to focus a new option; receives the option as a parameter.
labelKey, // Option labels are accessible with this string key.
options, // Array of options to render.
selectValue, // Callback to select a new option; receives the option as a parameter.
valueArray // Array of currently selected options.
```

### Further options


Expand Down Expand Up @@ -250,6 +263,7 @@ For multi-select inputs, when providing a custom `filterOptions` method, remembe
optionRenderer | func | undefined | function which returns a custom way to render the options in the menu
options | array | undefined | array of options
placeholder | string\|node | 'Select ...' | field placeholder, displayed when there's no value
renderMenu | func | undefined | Renders a custom menu with options; accepts the following named parameters: `renderMenu({ focusedOption, focusOption, options, selectValue, valueArray })`
searchable | bool | true | whether to enable searching feature or not
searchingText | string | 'Searching...' | message to display whilst options are loading via asyncOptions, or when `isLoading` is true
searchPromptText | string | 'Type to search' | label to prompt for search input
Expand Down
3 changes: 2 additions & 1 deletion examples/dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ var CitiesField = _react2['default'].createClass({
renderMenu: function renderMenu(_ref) {
var focusedOption = _ref.focusedOption;
var focusOption = _ref.focusOption;
var labelKey = _ref.labelKey;
var options = _ref.options;
var selectValue = _ref.selectValue;
var valueArray = _ref.valueArray;
Expand Down Expand Up @@ -160,7 +161,7 @@ var CitiesField = _react2['default'].createClass({
padding: '0 .5rem'
}
},
options[index].name
options[index][labelKey]
);
},
rowsCount: options.length,
Expand Down
1 change: 1 addition & 0 deletions examples/dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ var Select = _react2['default'].createClass({
return this.props.renderMenu({
focusedOption: focusedOption,
focusOption: this.focusOption,
labelKey: this.props.labelKey,
options: options,
selectValue: this.selectValue,
valueArray: valueArray
Expand Down
1 change: 1 addition & 0 deletions examples/dist/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ var Select = _react2['default'].createClass({
return this.props.renderMenu({
focusedOption: focusedOption,
focusOption: this.focusOption,
labelKey: this.props.labelKey,
options: options,
selectValue: this.selectValue,
valueArray: valueArray
Expand Down
4 changes: 2 additions & 2 deletions examples/src/components/Cities.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var CitiesField = React.createClass({
newState[e.target.name] = e.target.checked;
this.setState(newState);
},
renderMenu({ focusedOption, focusOption, options, selectValue, valueArray }) {
renderMenu({ focusedOption, focusOption, labelKey, options, selectValue, valueArray }) {
const focusedOptionIndex = options.indexOf(focusedOption);
const height = Math.min(MAX_OPTIONS_HEIGHT, options.length * OPTION_HEIGHT);

Expand All @@ -73,7 +73,7 @@ var CitiesField = React.createClass({
padding: '0 .5rem'
}}
>
{options[index].name}
{options[index][labelKey]}
</div>
)}
rowsCount={options.length}
Expand Down
1 change: 1 addition & 0 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ const Select = React.createClass({
return this.props.renderMenu({
focusedOption,
focusOption: this.focusOption,
labelKey: this.props.labelKey,
options,
selectValue: this.selectValue,
valueArray
Expand Down

0 comments on commit 071ae88

Please sign in to comment.