mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
add scroll handler when dropdown menu is attached
This commit is contained in:
@@ -51,7 +51,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<transition :name="transition">
|
<transition :name="transition">
|
||||||
<ul ref="dropdownMenu" v-if="dropdownOpen" class="vs__dropdown-menu" role="listbox" @mousedown="onMousedown" @mouseup="onMouseUp">
|
<ul
|
||||||
|
ref="dropdownMenu"
|
||||||
|
v-if="dropdownOpen"
|
||||||
|
class="vs__dropdown-menu"
|
||||||
|
role="listbox"
|
||||||
|
@mousedown="onMousedown"
|
||||||
|
@mouseup="onMouseUp"
|
||||||
|
>
|
||||||
<li
|
<li
|
||||||
role="option"
|
role="option"
|
||||||
v-for="(option, index) in filteredOptions"
|
v-for="(option, index) in filteredOptions"
|
||||||
@@ -299,6 +306,19 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler attached to the @scroll event of the
|
||||||
|
* dropdown menu.
|
||||||
|
* @type {Function}
|
||||||
|
*/
|
||||||
|
// onScroll: {
|
||||||
|
// type: Function,
|
||||||
|
// default(event) {
|
||||||
|
// console.debug(this);
|
||||||
|
// return this.$emit('scroll', event);
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable/disable creating options from searchEl.
|
* Enable/disable creating options from searchEl.
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
@@ -502,7 +522,15 @@
|
|||||||
*/
|
*/
|
||||||
multiple() {
|
multiple() {
|
||||||
this.clearSelection()
|
this.clearSelection()
|
||||||
}
|
},
|
||||||
|
|
||||||
|
dropdownOpen(open) {
|
||||||
|
this.$nextTick(function() {
|
||||||
|
if (open && typeof this.$refs.dropdownMenu !== 'undefined') {
|
||||||
|
this.$refs.dropdownMenu.onscroll = event => this.$emit('scroll', event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import { mountDefault } from '../helpers';
|
||||||
|
|
||||||
|
describe("Automatic Scrolling", () => {
|
||||||
|
it("should check if the scroll position needs to be adjusted on up arrow keyDown", () => {
|
||||||
|
const Select = mountDefault();
|
||||||
|
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
||||||
|
|
||||||
|
Select.vm.typeAheadPointer = 1;
|
||||||
|
|
||||||
|
Select.find({ ref: "search" }).trigger("keyup.up");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should check if the scroll position needs to be adjusted on down arrow keyDown", () => {
|
||||||
|
const Select = mountDefault();
|
||||||
|
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
||||||
|
|
||||||
|
Select.vm.typeAheadPointer = 1;
|
||||||
|
|
||||||
|
Select.find({ ref: "search" }).trigger("keyup.down");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test fails despite working in the browser.
|
||||||
|
* Many attempts to get it to pass.
|
||||||
|
*/
|
||||||
|
it.skip("should check if the scroll position needs to be adjusted when filtered options changes", () => {
|
||||||
|
const Select = mountDefault();
|
||||||
|
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
||||||
|
|
||||||
|
Select.vm.search = "two";
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should scroll up if the pointer is above the current viewport bounds", () => {
|
||||||
|
const Select = mountDefault();
|
||||||
|
const spy = jest.spyOn(Select.vm, "scrollTo");
|
||||||
|
|
||||||
|
Select.setMethods({
|
||||||
|
pixelsToPointerTop() {
|
||||||
|
return 1;
|
||||||
|
},
|
||||||
|
viewport() {
|
||||||
|
return { top: 2, bottom: 0 };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Select.vm.maybeAdjustScroll();
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalledWith(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should scroll down if the pointer is below the current viewport bounds", () => {
|
||||||
|
const Select = mountDefault();
|
||||||
|
const spy = jest.spyOn(Select.vm, "scrollTo");
|
||||||
|
|
||||||
|
Select.setMethods({
|
||||||
|
pixelsToPointerBottom() {
|
||||||
|
return 2;
|
||||||
|
},
|
||||||
|
viewport() {
|
||||||
|
return { top: 0, bottom: 1 };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Select.vm.maybeAdjustScroll();
|
||||||
|
expect(spy).toHaveBeenCalledWith(
|
||||||
|
Select.vm.viewport().top + Select.vm.pointerHeight()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('scroll events', () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -46,79 +46,6 @@ describe("Moving the Typeahead Pointer", () => {
|
|||||||
expect(Select.vm.typeAheadPointer).toEqual(2);
|
expect(Select.vm.typeAheadPointer).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Automatic Scrolling", () => {
|
|
||||||
it("should check if the scroll position needs to be adjusted on up arrow keyDown", () => {
|
|
||||||
const Select = mountDefault();
|
|
||||||
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
|
||||||
|
|
||||||
Select.vm.typeAheadPointer = 1;
|
|
||||||
|
|
||||||
Select.find({ ref: "search" }).trigger("keyup.up");
|
|
||||||
expect(spy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should check if the scroll position needs to be adjusted on down arrow keyDown", () => {
|
|
||||||
const Select = mountDefault();
|
|
||||||
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
|
||||||
|
|
||||||
Select.vm.typeAheadPointer = 1;
|
|
||||||
|
|
||||||
Select.find({ ref: "search" }).trigger("keyup.down");
|
|
||||||
expect(spy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This test fails despite working in the browser.
|
|
||||||
* After many attempts to get it to pass, it's been
|
|
||||||
* rewritten below.
|
|
||||||
*/
|
|
||||||
it.skip("should check if the scroll position needs to be adjusted when filtered options changes", () => {
|
|
||||||
const Select = mountDefault();
|
|
||||||
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
|
||||||
|
|
||||||
Select.vm.search = "two";
|
|
||||||
|
|
||||||
expect(spy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should scroll up if the pointer is above the current viewport bounds", () => {
|
|
||||||
const Select = mountDefault();
|
|
||||||
const spy = jest.spyOn(Select.vm, "scrollTo");
|
|
||||||
|
|
||||||
Select.setMethods({
|
|
||||||
pixelsToPointerTop() {
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
viewport() {
|
|
||||||
return { top: 2, bottom: 0 };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Select.vm.maybeAdjustScroll();
|
|
||||||
|
|
||||||
expect(spy).toHaveBeenCalledWith(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should scroll down if the pointer is below the current viewport bounds", () => {
|
|
||||||
const Select = mountDefault();
|
|
||||||
const spy = jest.spyOn(Select.vm, "scrollTo");
|
|
||||||
|
|
||||||
Select.setMethods({
|
|
||||||
pixelsToPointerBottom() {
|
|
||||||
return 2;
|
|
||||||
},
|
|
||||||
viewport() {
|
|
||||||
return { top: 0, bottom: 1 };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Select.vm.maybeAdjustScroll();
|
|
||||||
expect(spy).toHaveBeenCalledWith(
|
|
||||||
Select.vm.viewport().top + Select.vm.pointerHeight()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Measuring pixel distances", () => {
|
describe("Measuring pixel distances", () => {
|
||||||
it("should calculate pointerHeight as the offsetHeight of the pointer element if it exists", () => {
|
it("should calculate pointerHeight as the offsetHeight of the pointer element if it exists", () => {
|
||||||
const Select = mountDefault();
|
const Select = mountDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user