From 869d086b0f3fb30c69d006cc9f0a66d5d82c43f1 Mon Sep 17 00:00:00 2001 From: Eric Reynolds Date: Mon, 21 Sep 2015 14:44:04 -0700 Subject: [PATCH] Add the ability for categorization of react-select options --- .eslintrc | 2 +- README.md | 93 +- examples/src/components/CustomRenderField.js | 4 +- examples/src/components/MultiSelectField.js | 30 +- .../src/components/SelectedValuesField.js | 4 +- examples/src/components/StatesField.js | 8 +- .../src/components/ValuesAsNumbersField.js | 49 +- examples/src/data/states.js | 5 + less/control.less | 24 +- less/select.less | 5 + src/Select.js | 225 ++- test/Select-test.js | 1506 ++++++++++++++++- 12 files changed, 1866 insertions(+), 89 deletions(-) diff --git a/.eslintrc b/.eslintrc index 91a9bdce67..484fc5a615 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,7 +17,7 @@ "quotes": [2, "single", "avoid-escape"], "react/jsx-boolean-value": 1, "react/jsx-no-undef": 1, - "react/jsx-quotes": 1, + "jsx-quotes": 1, "react/jsx-sort-prop-types": 1, "react/jsx-uses-react": 1, "react/jsx-uses-vars": 1, diff --git a/README.md b/README.md index 27f19880ef..ef6d27e65e 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,32 @@ var getOptions = function(input, callback) { /> ``` +### Categorized Select + +You can utilize categorized selections by setting `categoized={true}`. In this mode: + +* You must pass in an object of arrays containing the options +* The keys of the object become to categories + +```js +var Select = require('react-select'); + +var options = { + "Primary": [ + { value: "blue", label: "Blue" }, + { value: "green", label: "Green" }, + { value: "red", label: "Red" } + ], + "Secondary": [ + { value: "yellow", label: "Yellow" }, + { value: "magenta", label: "Magenta" }, + { value: "cyan", label: "Cyan" } + ] +}; + + tag - noResultsText | string | placeholder displayed when there are no matching search results - onBlur | func | onBlur handler: function(event) {} - onChange | func | onChange handler: function(newValue) {} - onFocus | func | onFocus handler: function(event) {} - optionRenderer | func | function which returns a custom way to render the options in the menu - options | array | array of options - placeholder | string | field placeholder, displayed when there's no value - searchable | bool | whether to enable searching feature or not - searchPromptText | string | label to prompt for search input - value | any | initial field value - valueRenderer | func | function which returns a custom way to render the value selected + Property | Type | Description +:-----------------------|:------------------|:-------------------------------- + addLabelText | string | text to display when allowCreate is true + allowCreate | bool | allow new options to be created in multi mode (displays an "Add \