Skip to content

Commit ffd7559

Browse files
committed
Allow custom selections
1 parent 3503abc commit ffd7559

File tree

5 files changed

+784
-712
lines changed

5 files changed

+784
-712
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@ An example file is included with the module. Simply open `index.html` in a brows
7575
### Props
7676
Name | Type | Default | Description
7777
-----|------|---------|------------
78+
allowNew | boolean | false | Allows the creation of new selections on the fly. Note that any new items will be added to the list of selections, but not the list of original options unless handled as such by `Typeahead`'s parent.
7879
defaultSelected | array | `[]` | Specify any pre-selected options. Use only if you want the component to be uncontrolled.
7980
disabled | boolean | | Whether to disable the input. Will also disable selections when `multiple={true}`.
8081
emptyLabel | string | 'No matches found.' | Message to display in the menu if there are no valid results.
8182
labelKey | string | 'label' | Specify which option key to use for display. By default, the selector will use the `label` key.
8283
maxHeight | number | `300` | Maximum height of the dropdown menu, in px.
8384
multiple | boolean | `false` | Whether or not multiple selections are allowed.
85+
newSelectionPrefix | string | 'New selection:' | Provides the ability to specify a prefix before the user-entered text to indicate that the selection will be new. No-op unless `allowNew={true}`.
8486
options `required` | array | | Full set of options, including any pre-selected options.
8587
placeholder | string | | Placeholder text for the input.
86-
selected | array | `[]` | The selected option(s) displayed in the input. Use this prop if you want to control the component via it's parent.
88+
selected | array | `[]` | The selected option(s) displayed in the input. Use this prop if you want to control the component via its parent.
8789

8890
## Future Enhancements
8991
- [ ] Custom `Token` and `MenuItem` rendering

example/example.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Example = React.createClass({
7676
},
7777

7878
render() {
79-
const {disabled, multiple, preSelected, selected} = this.state;
79+
const {allowNew, disabled, multiple, preSelected, selected} = this.state;
8080

8181
return (
8282
<div>
@@ -87,6 +87,7 @@ const Example = React.createClass({
8787
</div>
8888
<div className="container">
8989
<Typeahead
90+
allowNew={allowNew}
9091
disabled={disabled}
9192
multiple={multiple}
9293
onChange={(selected) => this.setState({selected})}
@@ -130,6 +131,17 @@ const Example = React.createClass({
130131
Pre-Selected Options
131132
</label>
132133
</div>
134+
<div className="checkbox">
135+
<label>
136+
<input
137+
checked={allowNew}
138+
name="allowNew"
139+
onChange={this._handleChange}
140+
type="checkbox"
141+
/>
142+
Allow Custom Options
143+
</label>
144+
</div>
133145
</div>
134146
</div>
135147
<div style={{margin: '20px 0 0 0'}}>

0 commit comments

Comments
 (0)