Skip to content
Snippets Groups Projects
Commit dbb1382d authored by Sébastien DA ROCHA's avatar Sébastien DA ROCHA :bicyclist:
Browse files

Merge branch 'redmine-issue/11833' into 'develop'

REDMINE_ISSUE-11833

See merge request !82
parents 7ac02841 ade31e59
No related branches found
No related tags found
No related merge requests found
...@@ -12,16 +12,26 @@ ...@@ -12,16 +12,26 @@
v-if="search" v-if="search"
v-model="input" v-model="input"
v-on:keyup.enter="select(0)" v-on:keyup.enter="select(0)"
<<<<<<< HEAD
v-on:keyup.esc="toggleDropdown(false)"
=======
@input="handelInput" @input="handelInput"
>>>>>>> develop
class="search" class="search"
autocomplete="off" autocomplete="off"
tabindex="0" tabindex="0"
:placeholder="placehold" :placeholder="placehold"
<<<<<<< HEAD
ref="input"
/>
<div v-if="!input" class="default text">{{ selected }}</div>
=======
/> />
<!-- {{placeholder}} --> <!-- {{placeholder}} -->
<div v-if="!input" class="default text">{{ selected || placeholder }}</div> <div v-if="!input" class="default text">{{ selected || placeholder }}</div>
>>>>>>> develop
<i <i
:class="['dropdown icon', { clear: search && selected }]" :class="['dropdown icon', { clear: clearable && selected }]"
@click="clear" @click="clear"
></i> ></i>
<div :class="['menu', { 'visible transition': isOpen }]"> <div :class="['menu', { 'visible transition': isOpen }]">
...@@ -44,7 +54,14 @@ ...@@ -44,7 +54,14 @@
export default { export default {
name: "Dropdown", name: "Dropdown",
props: ["options", "selected", "disabled", "search", "placeholder"], props: [
"options",
"selected",
"disabled",
"search",
"placeholder",
"clearable",
],
computed: { computed: {
processedOptions: function () { processedOptions: function () {
...@@ -70,15 +87,27 @@ export default { ...@@ -70,15 +87,27 @@ export default {
identifier: 0, identifier: 0,
}; };
}, },
methods: { methods: {
toggleDropdown() { toggleDropdown(val) {
this.isOpen = !this.isOpen; if (this.isOpen) {
this.input = ""; // * clear input field when closing dropdown
} else if (this.search) {
//* focus on input if is a search dropdown
this.$refs.input.focus({
preventScroll: true,
});
} else if (this.clearable && val.target && this.selected) {
this.clear(); //* clear selected and input
}
this.isOpen = typeof val === "boolean" ? val : !this.isOpen;
}, },
select(index) { select(index) {
// * toggle dropdown is called several time, timeout delay this function to be the last
setTimeout(() => { setTimeout(() => {
this.isOpen = false; // * quick & dirty, car toggle dropdown est rappelé plusieurs fois aileurs, à creuser... this.isOpen = false;
}, 500); }, 0);
this.$emit("update:selection", this.options[index]); this.$emit("update:selection", this.options[index]);
this.input = ""; this.input = "";
}, },
...@@ -90,24 +119,16 @@ export default { ...@@ -90,24 +119,16 @@ export default {
}, },
clear() { clear() {
if (this.search) { if (this.clearable) {
this.input = ""; this.input = "";
this.clearSelected(); this.$emit("update:selection", "");
if (this.isOpen) this.toggleDropdown(false);
} }
}, },
clearSelected() {
this.$emit("update:selection", "");
},
handelInput() {
this.isOpen = true;
this.clearSelected();
},
clickOutsideDropdown(e) { clickOutsideDropdown(e) {
if (!e.target.closest(`#custom-dropdown${this.identifier}`)) if (!e.target.closest(`#custom-dropdown${this.identifier}`))
this.isOpen = false; this.toggleDropdown(false);
}, },
}, },
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
:selected="form.type.selected" :selected="form.type.selected"
:selection.sync="form.type.selected" :selection.sync="form.type.selected"
:search="true" :search="true"
:clearable="true"
/> />
</div> </div>
<div class="field wide four column no-padding-mobile no-margin-mobile"> <div class="field wide four column no-padding-mobile no-margin-mobile">
...@@ -105,6 +106,7 @@ ...@@ -105,6 +106,7 @@
:selected="form.status.selected.name" :selected="form.status.selected.name"
:selection.sync="form.status.selected" :selection.sync="form.status.selected"
:search="true" :search="true"
:clearable="true"
/> />
</div> </div>
<div class="field wide four column"> <div class="field wide four column">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment