-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
104 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters