mirror of
https://github.com/tenrok/vue-select.git
synced 2026-05-17 02:29:37 +03:00
Allow to disable options with selectable function (#921)
* allow to disable options with selectable function * add simple spec for new selectable option * Prevent non-selectable options from being keyboard navigatable
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { selectWithProps } from "../helpers";
|
||||
|
||||
describe("Selectable prop", () => {
|
||||
it("should select selectable option if clicked", () => {
|
||||
const Select = selectWithProps({
|
||||
options: ["one", "two", "three"],
|
||||
selectable: (option) => option == "one"
|
||||
});
|
||||
|
||||
Select.vm.$data.open = true;
|
||||
|
||||
Select.find(".vs__dropdown-menu li:first-child").trigger("mousedown");
|
||||
expect(Select.vm.selectedValue).toEqual(["one"]);
|
||||
})
|
||||
|
||||
it("should not select not selectable option if clicked", () => {
|
||||
const Select = selectWithProps({
|
||||
options: ["one", "two", "three"],
|
||||
selectable: (option) => option == "one"
|
||||
});
|
||||
|
||||
Select.vm.$data.open = true;
|
||||
|
||||
Select.find(".vs__dropdown-menu li:last-child").trigger("mousedown");
|
||||
expect(Select.vm.selectedValue).toEqual([]);
|
||||
});
|
||||
|
||||
it("should skip non-selectable option on down arrow keyUp", () => {
|
||||
const Select = selectWithProps({
|
||||
options: ["one", "two", "three"],
|
||||
selectable: (option) => option !== "two"
|
||||
});
|
||||
|
||||
Select.vm.typeAheadPointer = 1;
|
||||
|
||||
Select.find({ ref: "search" }).trigger("keyup.down");
|
||||
|
||||
expect(Select.vm.typeAheadPointer).toEqual(2);
|
||||
})
|
||||
|
||||
it("should skip non-selectable option on up arrow keyUp", () => {
|
||||
const Select = selectWithProps({
|
||||
options: ["one", "two", "three"],
|
||||
selectable: (option) => option !== "two"
|
||||
});
|
||||
|
||||
Select.vm.typeAheadPointer = 2;
|
||||
|
||||
Select.find({ ref: "search" }).trigger("keyup.up");
|
||||
|
||||
expect(Select.vm.typeAheadPointer).toEqual(0);
|
||||
})
|
||||
})
|
||||
@@ -18,7 +18,7 @@ describe("Moving the Typeahead Pointer", () => {
|
||||
expect(Select.vm.typeAheadPointer).toEqual(0);
|
||||
});
|
||||
|
||||
it("should move the pointer visually up the list on up arrow keyDown", () => {
|
||||
it("should move the pointer visually up the list on up arrow keyUp", () => {
|
||||
const Select = mountDefault();
|
||||
|
||||
Select.vm.typeAheadPointer = 1;
|
||||
@@ -28,7 +28,7 @@ describe("Moving the Typeahead Pointer", () => {
|
||||
expect(Select.vm.typeAheadPointer).toEqual(0);
|
||||
});
|
||||
|
||||
it("should move the pointer visually down the list on down arrow keyDown", () => {
|
||||
it("should move the pointer visually down the list on down arrow keyUp", () => {
|
||||
const Select = mountDefault();
|
||||
|
||||
Select.vm.typeAheadPointer = 1;
|
||||
@@ -47,7 +47,7 @@ describe("Moving the Typeahead Pointer", () => {
|
||||
});
|
||||
|
||||
describe("Automatic Scrolling", () => {
|
||||
it("should check if the scroll position needs to be adjusted on up arrow keyDown", () => {
|
||||
it("should check if the scroll position needs to be adjusted on up arrow keyUp", () => {
|
||||
const Select = mountDefault();
|
||||
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
||||
|
||||
@@ -57,7 +57,7 @@ describe("Moving the Typeahead Pointer", () => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should check if the scroll position needs to be adjusted on down arrow keyDown", () => {
|
||||
it("should check if the scroll position needs to be adjusted on down arrow keyUp", () => {
|
||||
const Select = mountDefault();
|
||||
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user