mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 20:19:05 +08:00
Improve the logic of the select and select_search components
> There is no need for the two components to hold their `value` state. It can be propagated from the component that uses them. This will help 'clear' the search when modification is finished.
This commit is contained in:
parent
478b731830
commit
9662eb7264
3 changed files with 9 additions and 7 deletions
|
@ -39,6 +39,7 @@
|
|||
</label>
|
||||
|
||||
<SelectSearch
|
||||
:value="selectedProject"
|
||||
ref="projectsSelector"
|
||||
@change="changeProject"
|
||||
:options="projects"
|
||||
|
@ -65,6 +66,7 @@
|
|||
</label>
|
||||
|
||||
<SelectSearch
|
||||
:value="selectedExperiment"
|
||||
:disabled="!selectedProject"
|
||||
ref="experimentsSelector"
|
||||
@change="changeExperiment"
|
||||
|
@ -88,6 +90,7 @@
|
|||
</label>
|
||||
|
||||
<SelectSearch
|
||||
:value="selectedTask"
|
||||
:disabled="!selectedExperiment"
|
||||
ref="tasksSelector"
|
||||
@change="changeTask"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
export default {
|
||||
name: 'Select',
|
||||
props: {
|
||||
value: { type: [String, Number] },
|
||||
options: { type: Array, default: () => [] },
|
||||
initialValue: { type: [String, Number] },
|
||||
placeholder: { type: String },
|
||||
|
@ -25,7 +26,6 @@
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
value: null,
|
||||
isOpen: false,
|
||||
optionPositionStyle: ''
|
||||
}
|
||||
|
@ -66,8 +66,7 @@
|
|||
}
|
||||
},
|
||||
setValue(value) {
|
||||
this.value = value;
|
||||
this.$emit('change', this.value);
|
||||
this.$emit('change', value);
|
||||
},
|
||||
updateOptionPosition() {
|
||||
const container = this.$refs.container;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<Select class="sn-select--search" :options="currentOptions" :placeholder="placeholder" v-bind:disabled="disabled" @change="change" @blur="blur" @open="open" @close="close">
|
||||
<Select class="sn-select--search" :value="value" :options="currentOptions" :placeholder="placeholder" v-bind:disabled="disabled" @change="change" @blur="blur" @open="open" @close="close">
|
||||
<input ref="focusElement" v-model="query" type="text" class="sn-select__search-input" :placeholder="searchPlaceholder" />
|
||||
<span class="sn-select__value">{{ valueLabel || (placeholder || i18n.t('general.select')) }}</span>
|
||||
<span class="sn-select__caret caret"></span>
|
||||
|
@ -12,6 +12,7 @@
|
|||
export default {
|
||||
name: 'SelectSearch',
|
||||
props: {
|
||||
value: { type: [String, Number] },
|
||||
options: { type: Array, default: () => [] },
|
||||
optionsUrl: { type: String },
|
||||
placeholder: { type: String },
|
||||
|
@ -21,7 +22,6 @@
|
|||
components: { Select },
|
||||
data() {
|
||||
return {
|
||||
value: null,
|
||||
query: null,
|
||||
currentOptions: null,
|
||||
isOpen: false
|
||||
|
@ -59,15 +59,15 @@
|
|||
this.$emit('blur');
|
||||
},
|
||||
change(value) {
|
||||
this.value = value;
|
||||
this.isOpen = false;
|
||||
this.$emit('change', this.value);
|
||||
this.$emit('change', value);
|
||||
},
|
||||
open() {
|
||||
this.isOpen = true;
|
||||
this.$emit('open');
|
||||
},
|
||||
close() {
|
||||
this.query = '';
|
||||
this.isOpen = false;
|
||||
this.$emit('close');
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue