Skip to content

Commit bd59aba

Browse files
author
Erez Makavy
authored
(fix)<MultiSelect> - Fix missing call to onManuallyInput when no options exists (#1804)
* Fix missing call to onManuallyInput when no options * clarify README
1 parent 33f4920 commit bd59aba

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/MultiSelect/MultiSelect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class MultiSelect extends InputWithOptions {
117117
}
118118

119119
if ((event.key === 'Enter' || event.key === 'Tab' || delimiters.includes(event.key)) && value.trim()) {
120+
this._onManuallyInput(this.state.inputValue);
120121
if (options.length) {
121-
this._onManuallyInput(this.state.inputValue);
122122
const unselectedOptions = this.getUnselectedOptions();
123123
const visibleOptions = unselectedOptions.filter(this.props.predicate);
124124
const maybeNearestOption = visibleOptions[0];

src/MultiSelect/MultiSelect.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ describe('multiSelect', () => {
211211
expect(onManuallyInput.mock.calls[0][0]).toBe('custom value');
212212
});
213213

214+
it('should call onManuallyInput after delimiter is pressed given no options', () => {
215+
const onManuallyInput = jest.fn();
216+
const {driver, inputDriver} = createDriver(<MultiSelect onManuallyInput={onManuallyInput} value="custom value"/>);
217+
218+
driver.focus();
219+
inputDriver.enterText('custom value');
220+
driver.pressCommaKey();
221+
222+
expect(onManuallyInput).toHaveBeenCalled();
223+
expect(onManuallyInput.mock.calls[0][0]).toBe('custom value');
224+
});
225+
214226
it('should call onRemoveTag when removing tags', () => {
215227
const tagId = 'SweetHome';
216228
const tags = [{id: tagId, label: 'Alabama'}];

src/MultiSelect/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| onChange | func | - | + | A callback function to be called when the input value changed|
1111
| value | string | - | - | The value of the current input |
1212
| onSelect | func | - | - | Callback function called whenever the user selects a single option or multiple options (with copy paste). The function receives array of values as an argument. |
13-
| onManuallyInput | func | noop | - | Callback when the user pressed the Enter key or Tab key after he wrote in the Input field - meaning the user selected something not in the list |
13+
| onManuallyInput | func | noop | - | Callback when the user pressed the Enter key or Tab key (or any given delimiter) after he wrote in the Input field - meaning the user selected something not in the list |
1414
| onRemoveTag | func | - | + | A callback function to be called when a tag should be removed|
1515
| tags | array of objects | - | + | The tags. tags are just set of selected suggestions|
1616
| placeholder | string | - | - | the placeholder for the input|

0 commit comments

Comments
 (0)