mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
enable custom logic for showing/hiding no options slot
This commit is contained in:
@@ -521,6 +521,26 @@ selectOnTab: {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## shouldNoOptionsSlotDisplay <Badge text="v3.13.0+" />
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* Determines whether the no options slot
|
||||||
|
* will be displayed.
|
||||||
|
*
|
||||||
|
* Receives the component instance as the only argument.
|
||||||
|
*
|
||||||
|
* @since v3.13.0
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
shouldNoOptionsSlotDisplay: {
|
||||||
|
type: Function,
|
||||||
|
default({ filteredOptions }) {
|
||||||
|
return filteredOptions.length === 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## tabindex
|
## tabindex
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
{{ getOptionLabel(option) }}
|
{{ getOptionLabel(option) }}
|
||||||
</slot>
|
</slot>
|
||||||
</li>
|
</li>
|
||||||
<li v-if="filteredOptions.length === 0" class="vs__no-options">
|
<li v-if="showNoOptionsSlot" class="vs__no-options">
|
||||||
<slot name="no-options" v-bind="scope.noOptions">Sorry, no matching options.</slot>
|
<slot name="no-options" v-bind="scope.noOptions">Sorry, no matching options.</slot>
|
||||||
</li>
|
</li>
|
||||||
<slot name="list-footer" v-bind="scope.listFooter" />
|
<slot name="list-footer" v-bind="scope.listFooter" />
|
||||||
@@ -579,6 +579,22 @@
|
|||||||
default({noDrop, open, mutableLoading}) {
|
default({noDrop, open, mutableLoading}) {
|
||||||
return noDrop ? false : open && !mutableLoading;
|
return noDrop ? false : open && !mutableLoading;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the no options slot
|
||||||
|
* will be displayed.
|
||||||
|
*
|
||||||
|
* Receives the component instance as the only argument.
|
||||||
|
*
|
||||||
|
* @since v3.13.0
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
noOptionsSlotShouldDisplay: {
|
||||||
|
type: Function,
|
||||||
|
default({filteredOptions}) {
|
||||||
|
return filteredOptions.length === 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1200,6 +1216,14 @@
|
|||||||
showClearButton() {
|
showClearButton() {
|
||||||
return !this.multiple && this.clearable && !this.open && !this.isValueEmpty
|
return !this.multiple && this.clearable && !this.open && !this.isValueEmpty
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the no options slot should be displayed.
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
showNoOptionsSlot() {
|
||||||
|
return !! this.noOptionsSlotShouldDisplay(this)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { mountDefault } from '../helpers';
|
import { mountDefault, selectWithProps } from '../helpers';
|
||||||
|
|
||||||
describe('Scoped Slots', () => {
|
describe('Scoped Slots', () => {
|
||||||
it('receives an option object to the selected-option-container slot', () => {
|
it('receives an option object to the selected-option-container slot', () => {
|
||||||
@@ -74,6 +74,20 @@ describe('Scoped Slots', () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('no options slot can be hidden', async () => {
|
||||||
|
const Select = selectWithProps({
|
||||||
|
noOptionsSlotShouldDisplay: () => false,
|
||||||
|
options: []
|
||||||
|
});
|
||||||
|
|
||||||
|
Select.vm.open = true;
|
||||||
|
await Select.vm.$nextTick();
|
||||||
|
|
||||||
|
expect(Select.classes('vs--open')).toBeTruthy();
|
||||||
|
expect(Select.find('.vs__dropdown-menu li')).toBeTruthy();
|
||||||
|
expect(Select.find('.vs__no-options').exists()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
test('header slot props', async () => {
|
test('header slot props', async () => {
|
||||||
const header = jest.fn();
|
const header = jest.fn();
|
||||||
const Select = mountDefault({}, {
|
const Select = mountDefault({}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user