mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-13 08:32:26 +03:00
feat: add dropdownShouldOpen prop (#1464)
This commit is contained in:
@@ -187,6 +187,21 @@ disabled: {
|
||||
},
|
||||
```
|
||||
|
||||
## dropdownShouldOpen <Badge text="v3.12.0+" />
|
||||
|
||||
Determines whether the dropdown should open. Used
|
||||
for overriding the default dropdown behaviour. Receives
|
||||
the vue-select instance as the single argument to the function.
|
||||
|
||||
```js
|
||||
dropdownShouldOpen: {
|
||||
type: Function,
|
||||
default({noDrop, open, mutableLoading}) {
|
||||
return noDrop ? false : open && !mutableLoading;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## filter
|
||||
|
||||
|
||||
@@ -565,6 +565,20 @@
|
||||
dropdownList.style.left = left;
|
||||
dropdownList.style.width = width;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines whether the dropdown should be open.
|
||||
* Receives the component instance as the only argument.
|
||||
*
|
||||
* @since v3.12.0
|
||||
* @return boolean
|
||||
*/
|
||||
dropdownShouldOpen: {
|
||||
type: Function,
|
||||
default({noDrop, open, mutableLoading}) {
|
||||
return noDrop ? false : open && !mutableLoading;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1132,7 +1146,7 @@
|
||||
* @return {Boolean} True if open
|
||||
*/
|
||||
dropdownOpen() {
|
||||
return this.noDrop ? false : this.open && !this.mutableLoading
|
||||
return this.dropdownShouldOpen(this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -188,4 +188,14 @@ describe("Toggling Dropdown", () => {
|
||||
expect(Select.classes('vs--searching')).toBeFalsy();
|
||||
});
|
||||
|
||||
it("can be opened with dropdownShouldOpen", () => {
|
||||
const Select = selectWithProps({
|
||||
noDrop: true,
|
||||
dropdownShouldOpen: () => true,
|
||||
options: ['one']
|
||||
});
|
||||
|
||||
expect(Select.classes('vs--open')).toBeTruthy();
|
||||
expect(Select.find('.vs__dropdown-menu li')).toBeTruthy();
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user