Skip to content

Commit

Permalink
feat(clearsearchonblur): add clearSearchOnBlur prop (#1077)
Browse files Browse the repository at this point in the history
Add docs, update tests from #1060.
  • Loading branch information
sagalbot authored Mar 2, 2020
1 parent 33104b5 commit 207c6d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
13 changes: 13 additions & 0 deletions docs/api/props.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ clearSearchOnSelect: {
},
```

## clearSearchOnBlur

Enables/disables clearing the search text when the search input is blurred.

```js
clearSearchOnBlur: {
type: Function,
default: function ({ clearSearchOnSelect, multiple }) {
return clearSearchOnSelect && !multiple
}
},
```

## closeOnSelect

Close a dropdown when an option is chosen. Set to false to keep the dropdown
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/ReactiveOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,28 @@ describe("Reset on options change", () => {
expect(Select.vm.selectedValue).toEqual([{ label: "oneLabel", value: "one" }]);
});

it('default behavior when blur search field is to clean it.', () => {
it('clearSearchOnBlur returns false when multiple is true', () => {
const Select = mountDefault({});
let clearSearchOnBlur = jest.spyOn(Select.vm, 'clearSearchOnBlur');
Select.find({ ref: "search" }).trigger("click");
Select.setData({ search: "one" });
Select.find({ ref: "search" }).trigger("blur");
Select.find({ref: 'search'}).trigger('click');
Select.setData({search: 'one'});
Select.find({ref: 'search'}).trigger('blur');

expect(clearSearchOnBlur).toHaveBeenCalledTimes(1);
expect(clearSearchOnBlur).toHaveBeenCalledWith({
clearSearchOnSelect: true,
multiple: false
multiple: false,
});
expect(Select.vm.search).toBe('');
});

it('control behavior when blur search field.', () => {
it('clearSearchOnBlur accepts a function', () => {
let clearSearchOnBlur = jest.fn(() => false);
const Select = mountDefault({clearSearchOnBlur});

Select.find({ ref: "search" }).trigger("click");
Select.setData({ search: "one" });
Select.find({ ref: "search" }).trigger("blur");
Select.find({ref: 'search'}).trigger('click');
Select.setData({search: 'one'});
Select.find({ref: 'search'}).trigger('blur');

expect(clearSearchOnBlur).toHaveBeenCalledTimes(1);
expect(Select.vm.search).toBe('one');
Expand Down

0 comments on commit 207c6d1

Please sign in to comment.