mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
fix: allow mouse events in the search input (#1092)
Co-authored-by: Doug Kurucz <doug.kurucz@twosixlabs.com> Co-authored-by: Jeff <sagalbot@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :dir="dir" class="v-select" :class="stateClasses">
|
<div :dir="dir" class="v-select" :class="stateClasses">
|
||||||
<slot name="header" v-bind="scope.header" />
|
<slot name="header" v-bind="scope.header" />
|
||||||
<div :id="`vs${uid}__combobox`" ref="toggle" @mousedown.prevent="toggleDropdown" class="vs__dropdown-toggle" role="combobox" :aria-expanded="dropdownOpen.toString()" :aria-owns="`vs${uid}__listbox`" aria-label="Search for option">
|
<div :id="`vs${uid}__combobox`" ref="toggle" @mousedown="toggleDropdown($event)" class="vs__dropdown-toggle" role="combobox" :aria-expanded="dropdownOpen.toString()" :aria-owns="`vs${uid}__listbox`" aria-label="Search for option">
|
||||||
|
|
||||||
<div class="vs__selected-options" ref="selectedOptions">
|
<div class="vs__selected-options" ref="selectedOptions">
|
||||||
<slot v-for="option in selectedValue"
|
<slot v-for="option in selectedValue"
|
||||||
@@ -731,22 +731,28 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle the visibility of the dropdown menu.
|
* Toggle the visibility of the dropdown menu.
|
||||||
* @param {Event} e
|
* @param {Event} event
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
toggleDropdown ({target}) {
|
toggleDropdown (event) {
|
||||||
|
const targetIsNotSearch = event.target !== this.$refs.search;
|
||||||
|
if (targetIsNotSearch) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
// don't react to click on deselect/clear buttons,
|
// don't react to click on deselect/clear buttons,
|
||||||
// they dropdown state will be set in their click handlers
|
// they dropdown state will be set in their click handlers
|
||||||
const ignoredButtons = [
|
const ignoredButtons = [
|
||||||
...(this.$refs['deselectButtons'] || []),
|
...(this.$refs['deselectButtons'] || []),
|
||||||
...([this.$refs['clearButton']] || [])
|
...([this.$refs['clearButton']] || []),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (ignoredButtons.some(ref => ref.contains(target) || ref === target)) {
|
if (ignoredButtons.some(ref => ref.contains(event.target) || ref === event.target)) {
|
||||||
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.open) {
|
if (this.open && targetIsNotSearch) {
|
||||||
this.searchEl.blur();
|
this.searchEl.blur();
|
||||||
} else if (!this.disabled) {
|
} else if (!this.disabled) {
|
||||||
this.open = true;
|
this.open = true;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ $font-size: 1em;
|
|||||||
width: 0;
|
width: 0;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.vs__search::placeholder {
|
.vs__search::placeholder {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
line-height: $vs-component-line-height;
|
line-height: $vs-component-line-height;
|
||||||
margin: 4px 2px 0px 2px;
|
margin: 4px 2px 0px 2px;
|
||||||
padding: 0 0.25em;
|
padding: 0 0.25em;
|
||||||
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.vs__deselect {
|
.vs__deselect {
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { selectWithProps } from "../helpers";
|
import { selectWithProps } from "../helpers";
|
||||||
import OpenIndicator from "../../src/components/OpenIndicator";
|
import OpenIndicator from "../../src/components/OpenIndicator";
|
||||||
|
|
||||||
|
const preventDefault = jest.fn()
|
||||||
|
|
||||||
|
function clickEvent (currentTarget) {
|
||||||
|
return { currentTarget, preventDefault }
|
||||||
|
}
|
||||||
|
|
||||||
describe("Toggling Dropdown", () => {
|
describe("Toggling Dropdown", () => {
|
||||||
it("should not open the dropdown when the el is clicked but the component is disabled", () => {
|
it("should not open the dropdown when the el is clicked but the component is disabled", () => {
|
||||||
const Select = selectWithProps({ disabled: true });
|
const Select = selectWithProps({ disabled: true });
|
||||||
Select.vm.toggleDropdown({ target: Select.vm.$refs.search });
|
Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
|
||||||
expect(Select.vm.open).toEqual(false);
|
expect(Select.vm.open).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -14,10 +20,23 @@ describe("Toggling Dropdown", () => {
|
|||||||
options: [{ label: "one" }]
|
options: [{ label: "one" }]
|
||||||
});
|
});
|
||||||
|
|
||||||
Select.vm.toggleDropdown({ target: Select.vm.$refs.search });
|
Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
|
||||||
expect(Select.vm.open).toEqual(true);
|
expect(Select.vm.open).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not close the dropdown when the el is clicked and enableMouseInputSearch is set to true", () => {
|
||||||
|
const Select = selectWithProps({
|
||||||
|
value: [{ label: "one" }],
|
||||||
|
options: [{ label: "one" }],
|
||||||
|
enableMouseSearchInput: true
|
||||||
|
});
|
||||||
|
|
||||||
|
Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
|
||||||
|
expect(Select.vm.open).toEqual(true);
|
||||||
|
Select.vm.toggleDropdown(clickEvent(Select.vm.$el));
|
||||||
|
expect(Select.vm.open).toEqual(false)
|
||||||
|
});
|
||||||
|
|
||||||
it("should open the dropdown when the selected tag is clicked", () => {
|
it("should open the dropdown when the selected tag is clicked", () => {
|
||||||
const Select = selectWithProps({
|
const Select = selectWithProps({
|
||||||
value: [{ label: "one" }],
|
value: [{ label: "one" }],
|
||||||
@@ -26,7 +45,7 @@ describe("Toggling Dropdown", () => {
|
|||||||
|
|
||||||
const selectedTag = Select.find(".vs__selected").element;
|
const selectedTag = Select.find(".vs__selected").element;
|
||||||
|
|
||||||
Select.vm.toggleDropdown({ target: selectedTag });
|
Select.vm.toggleDropdown(clickEvent(selectedTag));
|
||||||
expect(Select.vm.open).toEqual(true);
|
expect(Select.vm.open).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -35,7 +54,7 @@ describe("Toggling Dropdown", () => {
|
|||||||
const spy = jest.spyOn(Select.vm.$refs.search, "blur");
|
const spy = jest.spyOn(Select.vm.$refs.search, "blur");
|
||||||
|
|
||||||
Select.vm.open = true;
|
Select.vm.open = true;
|
||||||
Select.vm.toggleDropdown({ target: Select.vm.$el });
|
Select.vm.toggleDropdown(clickEvent(Select.vm.$el));
|
||||||
|
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -133,7 +152,9 @@ describe("Toggling Dropdown", () => {
|
|||||||
const Select = selectWithProps({
|
const Select = selectWithProps({
|
||||||
noDrop: true,
|
noDrop: true,
|
||||||
});
|
});
|
||||||
Select.vm.toggleDropdown({ target: Select.vm.$refs.search });
|
|
||||||
|
Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
|
||||||
|
|
||||||
expect(Select.vm.open).toEqual(true);
|
expect(Select.vm.open).toEqual(true);
|
||||||
await Select.vm.$nextTick();
|
await Select.vm.$nextTick();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user