diff --git a/demo/components/selectDemo/index.vue b/demo/components/selectDemo/index.vue index a809019ea..ad970d06a 100644 --- a/demo/components/selectDemo/index.vue +++ b/demo/components/selectDemo/index.vue @@ -17,6 +17,7 @@ + @@ -28,6 +29,7 @@ import multipleSelect from './multipleSelect.demo.vue' import changeEvent from './changeEvent.demo' import changeEventEmitItem from './changeEventEmitItem.demo' import search from './search.demo.vue' +import remoteSearch from './remoteSearch.demo.vue' export default { components: { @@ -36,7 +38,8 @@ export default { changeEvent, changeEventEmitItem, search, - disabled + disabled, + remoteSearch }, data () { return { diff --git a/demo/components/selectDemo/remoteSearch.demo.vue b/demo/components/selectDemo/remoteSearch.demo.vue new file mode 100644 index 000000000..eb6a14bdd --- /dev/null +++ b/demo/components/selectDemo/remoteSearch.demo.vue @@ -0,0 +1,107 @@ + + + diff --git a/packages/common/Select/src/MultipleSelect.vue b/packages/common/Select/src/MultipleSelect.vue index 87d8140c1..bd1b8700a 100644 --- a/packages/common/Select/src/MultipleSelect.vue +++ b/packages/common/Select/src/MultipleSelect.vue @@ -4,9 +4,9 @@ class="n-select" :class="{ [`n-select--${size}-size`]: true, + [`n-select--remote`]: remote, 'n-select--disabled': disabled }" - :style="{'cursor':cursor}" @click="handleActivatorClick" @keyup.up.prevent="handleActivatorKeyUpUp" @keyup.down.prevent="handleActivatorKeyUpDown" @@ -63,9 +63,6 @@ @@ -103,24 +100,26 @@ :style="{ top: `${lightBarTop}px` }" /> +
- {{ item.label }} -
-
{{ /** @@ -129,7 +128,25 @@ */ hideLightBar() }} - none result matched + loading +
+
+ {{ + hideLightBar() + }} + {{ noDataContent }} +
+
+ {{ + hideLightBar() + }} + {{ notFoundContent }}
@@ -203,9 +220,25 @@ export default { type: Boolean, default: false }, - cursor: { - type: String, - default: 'inherit' + remote: { + type: Boolean, + default: false + }, + onSearch: { + type: Function, + default: null + }, + loading: { + type: Boolean, + default: false + }, + noDataContent: { + type: [String, Function], + default: 'no data' + }, + notFoundContent: { + type: [String, Function], + default: 'none result matched' } }, data () { @@ -215,21 +248,19 @@ export default { scrolling: false, pattern: '', pendingItem: null, - pendingItemIndex: null + pendingItemIndex: null, + memorizedValueItemMap: new Map() } }, computed: { filteredItems () { - if (!this.filterable || !this.pattern.trim().length) return this.items + if (this.remote) { + return this.items + } else if (!this.filterable || !this.pattern.trim().length) return this.items return this.items.filter(item => this.patternMatched(item.label)) }, selected () { - if (Array.isArray(this.value)) { - const itemValues = new Set(this.items.map(item => item.value)) - return this.value.filter(value => itemValues.has(value)).length - } else { - return false - } + return this.selectedItems.length }, valueItemMap () { const valueToItem = new Map() @@ -238,7 +269,13 @@ export default { }, selectedItems () { if (!Array.isArray(this.value)) return [] - return this.value.filter(value => this.valueItemMap.has(value)).map(value => this.valueItemMap.get(value)) + if (this.remote) { + return this.value + .filter(value => this.valueItemMap.has(value) || this.memorizedValueItemMap.has(value)) + .map(value => this.valueItemMap.has(value) ? this.valueItemMap.get(value) : this.memorizedValueItemMap.get(value)) + } else { + return this.value.filter(value => this.valueItemMap.has(value)).map(value => this.valueItemMap.get(value)) + } }, clearedPattern () { return this.pattern.toLowerCase().trim() @@ -332,10 +369,13 @@ export default { }, toggleItem (item) { if (this.disabled) return + if (this.remote) { + this.memorizedValueItemMap.set(item.value, item) + } let newValue = [] if (Array.isArray(this.value)) { const itemValues = new Set(this.items.map(item => item.value)) - newValue = this.value.filter(value => itemValues.has(value)) + newValue = this.value.filter(value => itemValues.has(value) || this.memorizedValueItemMap.has(value)) } const index = newValue.findIndex(value => value === item.value) if (~index) { @@ -365,6 +405,9 @@ export default { this.$nextTick().then(() => { const textWidth = this.$refs.inputTagMirror.getBoundingClientRect().width this.$refs.inputTagInput.style.width = textWidth + 'px' + if (this.onSearch) { + this.onSearch(this.pattern) + } }) }, handlePatternInputDelete (e) { diff --git a/packages/common/Select/src/SingleSelect.vue b/packages/common/Select/src/SingleSelect.vue index 7572fa4c7..2c22a56bd 100644 --- a/packages/common/Select/src/SingleSelect.vue +++ b/packages/common/Select/src/SingleSelect.vue @@ -6,7 +6,6 @@ [`n-select--${size}-size`]: true, 'n-select--disabled': disabled }" - :style="{'cursor':cursor}" @click="toggleMenu" >