Skip to content

Commit ef03b59

Browse files
committed
Update to v0.1.6
1 parent 373b713 commit ef03b59

10 files changed

+216
-124
lines changed

build/react-bootstrap-typeahead.js

Lines changed: 129 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/react-bootstrap-typeahead.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/react-bootstrap-typeahead.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/react-bootstrap-typeahead.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Token.react.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var Token = _react2.default.createClass({
5151
};
5252
},
5353
render: function render() {
54-
return this.props.onRemove ? this._renderRemoveableToken() : this._renderToken();
54+
return this.props.onRemove && !this.props.disabled ? this._renderRemoveableToken() : this._renderToken();
5555
},
5656
_renderRemoveableToken: function _renderRemoveableToken() {
5757
return _react2.default.createElement(
@@ -68,25 +68,30 @@ var Token = _react2.default.createClass({
6868
this.props.children,
6969
_react2.default.createElement(
7070
'span',
71-
{ className: 'token-close-button', onClick: this._handleRemove },
71+
{ className: 'close-button', onClick: this._handleRemove },
7272
'×'
7373
)
7474
);
7575
},
7676
_renderToken: function _renderToken() {
77-
var classnames = (0, _classnames2.default)('token', this.props.className);
77+
var _props = this.props;
78+
var className = _props.className;
79+
var disabled = _props.disabled;
80+
var href = _props.href;
7881

79-
if (this.props.href) {
82+
var classnames = (0, _classnames2.default)('token', className);
83+
84+
if (href) {
8085
return _react2.default.createElement(
8186
'a',
82-
{ className: classnames, href: this.props.href },
87+
{ className: classnames, disabled: disabled, href: href },
8388
this.props.children
8489
);
8590
}
8691

8792
return _react2.default.createElement(
8893
'div',
89-
{ className: classnames },
94+
{ className: classnames, disabled: disabled },
9095
this.props.children
9196
);
9297
},

lib/TokenizerInput.react.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
3232

3333
var PropTypes = _react2.default.PropTypes;
3434

35-
require('../css/Tokenizer.css');
36-
3735
/**
3836
* TokenizerInput
3937
*
4038
* Accepts multiple selections from a Typeahead component and renders them as
4139
* tokens within an input.
4240
*/
41+
4342
var TokenizerInput = _react2.default.createClass({
4443
displayName: 'TokenizerInput',
4544

4645
propTypes: {
46+
disabled: PropTypes.bool,
4747
labelKey: PropTypes.string,
4848
/**
4949
* Input element placeholder text.
@@ -55,6 +55,7 @@ var TokenizerInput = _react2.default.createClass({
5555
render: function render() {
5656
var _props = this.props;
5757
var className = _props.className;
58+
var disabled = _props.disabled;
5859
var placeholder = _props.placeholder;
5960
var selected = _props.selected;
6061
var text = _props.text;
@@ -63,15 +64,17 @@ var TokenizerInput = _react2.default.createClass({
6364
'div',
6465
{
6566
className: (0, _classnames2.default)('bootstrap-tokenizer', 'form-control', 'clearfix', className),
67+
disabled: disabled,
6668
onClick: this._handleInputFocus,
6769
onFocus: this._handleInputFocus,
68-
tabIndex: 0 },
70+
tabIndex: disabled ? -1 : 0 },
6971
selected.map(this._renderToken),
7072
_react2.default.createElement(_reactInputAutosize2.default, _extends({}, this.props, {
7173
className: 'bootstrap-tokenizer-input',
7274
inputStyle: {
7375
backgroundColor: 'inherit',
7476
border: 0,
77+
cursor: 'inherit',
7578
outline: 'none',
7679
padding: 0
7780
},
@@ -85,12 +88,14 @@ var TokenizerInput = _react2.default.createClass({
8588
},
8689
_renderToken: function _renderToken(option, idx) {
8790
var _props2 = this.props;
88-
var onRemove = _props2.onRemove;
91+
var disabled = _props2.disabled;
8992
var labelKey = _props2.labelKey;
93+
var onRemove = _props2.onRemove;
9094

9195
return _react2.default.createElement(
9296
_Token2.default,
9397
{
98+
disabled: disabled,
9499
key: idx,
95100
onRemove: onRemove.bind(null, option) },
96101
option[labelKey]
@@ -118,7 +123,12 @@ var TokenizerInput = _react2.default.createClass({
118123
this.props.onKeyDown && this.props.onKeyDown(e);
119124
},
120125

121-
_handleInputFocus: function _handleInputFocus(e) {
126+
_handleInputFocus: function _handleInputFocus(e, e2, e3) {
127+
if (this.props.disabled) {
128+
e.target.blur();
129+
return;
130+
}
131+
122132
// If the user clicks anywhere inside the tokenizer besides a token,
123133
// focus the input.
124134
this.refs.input.focus();

lib/Typeahead.react.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ var Typeahead = _react2.default.createClass({
4343
mixins: [_reactOnclickoutside2.default],
4444

4545
propTypes: {
46+
/**
47+
* Allows the creation of new selections on the fly. Note that any new items
48+
* will be added to the list of selections, but not the list of original
49+
* options unless handled as such by `Typeahead`'s parent.
50+
*/
51+
allowNew: PropTypes.bool,
52+
/**
53+
* Specify any pre-selected options. Use only if you want the component to
54+
* be uncontrolled.
55+
*/
4656
defaultSelected: PropTypes.array,
57+
/**
58+
* Whether to disable the input. Will also disable selections when
59+
* `multiple={true}`.
60+
*/
61+
disabled: PropTypes.bool,
4762
/**
4863
* Message to display in the menu if there are no valid results.
4964
*/
@@ -53,21 +68,37 @@ var Typeahead = _react2.default.createClass({
5368
* will use the `label` key.
5469
*/
5570
labelKey: PropTypes.string,
71+
/**
72+
* Maximum height of the dropdown menu, in px.
73+
*/
5674
maxHeight: PropTypes.number,
5775
/**
5876
* Whether or not multiple selections are allowed.
5977
*/
6078
multiple: PropTypes.bool,
79+
/**
80+
* Provides the ability to specify a prefix before the user-entered text to
81+
* indicate that the selection will be new. No-op unless `allowNew={true}`.
82+
*/
83+
newSelectionPrefix: PropTypes.string,
6184
/**
6285
* Full set of options, including pre-selected options.
6386
*/
6487
options: PropTypes.array.isRequired,
88+
/**
89+
* Placeholder text for the input.
90+
*/
6591
placeholder: PropTypes.string,
92+
/**
93+
* The selected option(s) displayed in the input. Use this prop if you want
94+
* to control the component via its parent.
95+
*/
6696
selected: PropTypes.array
6797
},
6898

6999
getDefaultProps: function getDefaultProps() {
70100
return {
101+
allowNew: false,
71102
defaultSelected: [],
72103
labelKey: 'label',
73104
multiple: false,
@@ -114,6 +145,15 @@ var Typeahead = _react2.default.createClass({
114145
return !(option[labelKey].toLowerCase().indexOf(text.toLowerCase()) === -1 || multiple && (0, _lodash.find)(selected, option));
115146
});
116147

148+
if (!filteredOptions.length && this.props.allowNew) {
149+
var newOption = {
150+
id: (0, _lodash.uniqueId)('new-id-'),
151+
customOption: true
152+
};
153+
newOption[labelKey] = text;
154+
filteredOptions = [newOption];
155+
}
156+
117157
var menu = undefined;
118158
if (this.state.showMenu) {
119159
menu = _react2.default.createElement(_TypeaheadMenu2.default, {
@@ -140,6 +180,7 @@ var Typeahead = _react2.default.createClass({
140180
className: 'bootstrap-typeahead open',
141181
style: { position: 'relative' } },
142182
_react2.default.createElement(InputComponent, {
183+
disabled: this.props.disabled,
143184
filteredOptions: filteredOptions,
144185
labelKey: labelKey,
145186
onAdd: this._handleAddOption,

lib/TypeaheadInput.react.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
2828

2929
var PropTypes = _react2.default.PropTypes;
3030

31-
require('../css/Typeahead.css');
32-
3331
/**
3432
* TypeaheadInput
3533
*
3634
* Handles a single selection from the Typeahead component.
3735
*/
36+
3837
var TypeaheadInput = _react2.default.createClass({
3938
displayName: 'TypeaheadInput',
4039

4140
mixins: [_reactOnclickoutside2.default],
4241

4342
propTypes: {
43+
disabled: PropTypes.bool,
4444
filteredOptions: PropTypes.array,
4545
labelKey: PropTypes.string,
4646
onChange: PropTypes.func,
@@ -55,6 +55,7 @@ var TypeaheadInput = _react2.default.createClass({
5555
className: (0, _classnames2.default)('bootstrap-typeahead-input', this.props.className),
5656
onClick: this._handleInputFocus,
5757
onFocus: this._handleInputFocus,
58+
style: { outline: 'none' },
5859
tabIndex: 0 },
5960
_react2.default.createElement('input', _extends({}, this.props, {
6061
className: (0, _classnames2.default)('bootstrap-typeahead-input-main', 'form-control', {
@@ -63,7 +64,7 @@ var TypeaheadInput = _react2.default.createClass({
6364
onKeyDown: this._handleKeydown,
6465
ref: 'input',
6566
style: {
66-
backgroundColor: 'transparent',
67+
backgroundColor: !this.props.disabled && 'transparent',
6768
display: 'block',
6869
position: 'relative',
6970
zIndex: 1
@@ -76,6 +77,7 @@ var TypeaheadInput = _react2.default.createClass({
7677
style: {
7778
borderColor: 'transparent',
7879
bottom: 0,
80+
boxShadow: 'none',
7981
display: 'block',
8082
position: 'absolute',
8183
top: 0,

lib/TypeaheadMenu.react.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ var TypeaheadMenu = _react2.default.createClass({
7070
emptyLabel: PropTypes.string,
7171
labelKey: PropTypes.string.isRequired,
7272
maxHeight: PropTypes.number,
73+
newSelectionPrefix: PropTypes.string,
7374
options: PropTypes.array
7475
},
7576

7677
getDefaultProps: function getDefaultProps() {
7778
return {
7879
emptyLabel: 'No matches found.',
79-
maxHeight: 300
80+
maxHeight: 300,
81+
newSelectionPrefix: 'New selection:'
8082
};
8183
},
8284
render: function render() {
@@ -103,15 +105,21 @@ var TypeaheadMenu = _react2.default.createClass({
103105
_renderDropdownItem: function _renderDropdownItem(option, idx) {
104106
var _props2 = this.props;
105107
var activeIndex = _props2.activeIndex;
108+
var newSelectionPrefix = _props2.newSelectionPrefix;
106109
var onClick = _props2.onClick;
107110

111+
var label = option[this.props.labelKey];
112+
if (option.customOption) {
113+
label = newSelectionPrefix + ' ' + label;
114+
}
115+
108116
return _react2.default.createElement(
109117
MenuItem,
110118
{
111119
active: idx === activeIndex,
112120
key: idx,
113121
onClick: onClick.bind(null, option) },
114-
option[this.props.labelKey]
122+
label
115123
);
116124
}
117125
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-bootstrap-typeahead",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "React-based typeahead using the Bootstrap theme",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)