Skip to content

Commit eb2f8f8

Browse files
authored
- bind scope to open-indicator-icon slot (sagalbot#860)
- explicitly set v-if on OpenIndicator - only add searching and searchable state classes if noDrop is false - only add OpenIndicator to toggleTargets if the $ref exists
1 parent 7d72db3 commit eb2f8f8

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

src/components/Select.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
<component :is="childComponents.Deselect" />
4141
</button>
4242

43-
<slot name="open-indicator-icon">
44-
<component :is="childComponents.OpenIndicator" v-bind="scope.openIndicator.attributes"/>
43+
<slot name="open-indicator-icon" v-bind="scope.openIndicator">
44+
<component :is="childComponents.OpenIndicator" v-if="!noDrop" v-bind="scope.openIndicator.attributes"/>
4545
</slot>
4646

4747
<slot name="spinner" v-bind="scope.spinner">
@@ -562,11 +562,16 @@
562562
this.$el,
563563
this.searchEl,
564564
this.$refs.toggle.$el,
565-
this.$refs.openIndicator.$el,
566-
// the line below is a bit gross, but required to support IE11 without adding polyfills
567-
...Array.prototype.slice.call(this.$refs.openIndicator.$el.childNodes)
568565
];
569566
567+
if (typeof this.$refs.openIndicator !== 'undefined') {
568+
toggleTargets.push(
569+
this.$refs.openIndicator.$el,
570+
// the line below is a bit gross, but required to support IE11 without adding polyfills
571+
...Array.prototype.slice.call(this.$refs.openIndicator.$el.childNodes),
572+
);
573+
}
574+
570575
if (toggleTargets.indexOf(target) > -1 || target.classList.contains('vs__selected')) {
571576
if (this.open) {
572577
this.searchEl.blur(); // dropdown will close on blur
@@ -890,7 +895,6 @@
890895
},
891896
openIndicator: {
892897
attributes: {
893-
'v-if': !this.noDrop,
894898
'ref': 'openIndicator',
895899
'role': 'presentation',
896900
'class': 'vs__open-indicator',
@@ -921,8 +925,8 @@
921925
return {
922926
'vs--open': this.dropdownOpen,
923927
'vs--single': !this.multiple,
924-
'vs--searching': this.searching,
925-
'vs--searchable': this.searchable,
928+
'vs--searching': this.searching && !this.noDrop,
929+
'vs--searchable': this.searchable && !this.noDrop,
926930
'vs--unsearchable': !this.searchable,
927931
'vs--loading': this.mutableLoading,
928932
'vs--disabled': this.disabled

tests/unit/Dropdown.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { selectWithProps } from "../helpers";
2+
import OpenIndicator from "../../src/components/OpenIndicator";
23

34
describe("Toggling Dropdown", () => {
45
it("should not open the dropdown when the el is clicked but the component is disabled", () => {
@@ -127,4 +128,40 @@ describe("Toggling Dropdown", () => {
127128
Select.vm.open = true;
128129
expect(Select.vm.stateClasses['vs--open']).toEqual(true);
129130
});
131+
132+
it("should not display the dropdown if noDrop is true", () => {
133+
const Select = selectWithProps({
134+
noDrop: true,
135+
});
136+
137+
Select.vm.toggleDropdown({ target: Select.vm.$refs.search });
138+
expect(Select.vm.open).toEqual(true);
139+
expect(Select.contains('.vs__dropdown-menu')).toBeFalsy();
140+
expect(Select.vm.stateClasses['vs--open']).toBeFalsy();
141+
});
142+
143+
it("should hide the open indicator if noDrop is true", () => {
144+
const Select = selectWithProps({
145+
noDrop: true,
146+
});
147+
expect(Select.contains(OpenIndicator)).toBeFalsy();
148+
});
149+
150+
it("should not add the searchable state class when noDrop is true", () => {
151+
const Select = selectWithProps({
152+
noDrop: true,
153+
});
154+
expect(Select.classes('vs--searchable')).toBeFalsy();
155+
});
156+
157+
it("should not add the searching state class when noDrop is true", () => {
158+
const Select = selectWithProps({
159+
noDrop: true,
160+
});
161+
162+
Select.vm.search = 'Canada';
163+
164+
expect(Select.classes('vs--searching')).toBeFalsy();
165+
});
166+
130167
});

0 commit comments

Comments
 (0)