diff --git a/docs/api/props.md b/docs/api/props.md index 999e935..cfe3aca 100644 --- a/docs/api/props.md +++ b/docs/api/props.md @@ -187,6 +187,21 @@ disabled: { }, ``` +## dropdownShouldOpen + +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 diff --git a/src/components/Select.vue b/src/components/Select.vue index 0eede03..c73b6a7 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -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); }, /** diff --git a/tests/unit/Dropdown.spec.js b/tests/unit/Dropdown.spec.js index c73b2e1..7404284 100755 --- a/tests/unit/Dropdown.spec.js +++ b/tests/unit/Dropdown.spec.js @@ -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(); + }) });