|
13 | 13 | @keydown="keyDown"
|
14 | 14 | @keyup="keyUp"
|
15 | 15 | @click="update"
|
16 |
| - @onpaste="onPaste" |
| 16 | + @paste="onPaste" |
17 | 17 | v-bind="remaining">
|
18 | 18 |
|
19 | 19 | <button type="button" @click="toggle" class="absolute inset-y-0 right-0 flex items-center rounded-r-md px-2 focus:outline-none" tabindex="-1">
|
@@ -107,15 +107,10 @@ const take = ref(props.viewCount)
|
107 | 107 | const filteredValues = ref<any[]>([])
|
108 | 108 |
|
109 | 109 | const filteredOptions = computed(() => {
|
110 |
| - try { |
111 |
| - let ret = !inputValue.value |
112 |
| - ? props.options |
113 |
| - : props.options.filter(x => props.match(x, inputValue.value)).slice(0,take.value) |
114 |
| - return ret |
115 |
| - } catch(e) { |
116 |
| - console.log('filteredOptions error', e) |
117 |
| - } |
118 |
| - return [] |
| 110 | + let ret = !inputValue.value |
| 111 | + ? props.options |
| 112 | + : props.options.filter(x => props.match(x, inputValue.value)).slice(0,take.value) |
| 113 | + return ret |
119 | 114 | })
|
120 | 115 |
|
121 | 116 | const navKeys = ['Tab', 'Escape', 'ArrowDown', 'ArrowUp', 'Enter', 'PageUp', 'PageDown', 'Home', 'End']
|
@@ -147,12 +142,23 @@ function handlePastedText(txt?:string) {
|
147 | 142 | focusNextElement()
|
148 | 143 | }
|
149 | 144 | } else if (multipleValues) {
|
150 |
| - const re = new RegExp(`\\n|\\t|,`) |
| 145 | + const re = new RegExp(`\\r|\\n|\\t|,`) |
151 | 146 | const values = txt.split(re).filter(x => x.trim())
|
152 | 147 | const matches = values.map(value => props.options.find(x => props.match(x,value))).filter(x => !!x)
|
| 148 | + console.log('values', values, matches) |
153 | 149 | if (matches.length > 0) {
|
154 |
| - matches.forEach(select) |
| 150 | + inputValue.value = '' |
155 | 151 | showPopup.value = false
|
| 152 | + active.value = null |
| 153 | + let newValues = Array.from(props.modelValue || []) |
| 154 | + matches.forEach(option => { |
| 155 | + if (hasOption(option)) { |
| 156 | + newValues = newValues.filter(x => x != option) |
| 157 | + } else { |
| 158 | + newValues.push(option) |
| 159 | + } |
| 160 | + }) |
| 161 | + emit('update:modelValue', newValues) |
156 | 162 | focusNextElement()
|
157 | 163 | }
|
158 | 164 | }
|
@@ -252,8 +258,6 @@ function update() {
|
252 | 258 | }
|
253 | 259 |
|
254 | 260 | function select(option:any) {
|
255 |
| - console.log('select', option) |
256 |
| -
|
257 | 261 | inputValue.value = ''
|
258 | 262 | showPopup.value = false
|
259 | 263 |
|
|
0 commit comments