Skip to content

Commit

Permalink
feat(select): support use backspace to delete tag
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Aug 2, 2022
1 parent 31d1cd8 commit f05e8f4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion components/select/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
role="combobox"
aria-autocomplete="list"
@input="handleFilterInput"
@keydown="handleBackspace"
/>
<span ref="device" :class="nh.be('device')" aria-hidden="true">
{{ currentFilter }}
Expand Down Expand Up @@ -914,9 +915,20 @@ export default defineComponent({
anchorWidth.value = range.getBoundingClientRect().width
}
updatePopper()
})
}
function handleBackspace(event: KeyboardEvent) {
if (!input.value) return
if (event.key === 'Backspace' && !input.value.value && !isNull(currentValues.value.at(-1))) {
event.stopPropagation()
handleTagClose(currentValues.value.at(-1)!)
}
}
return {
props,
nh,
Expand Down Expand Up @@ -957,7 +969,8 @@ export default defineComponent({
handleClear,
handleFocus,
handleBlur,
handleFilterInput
handleFilterInput,
handleBackspace
}
}
})
Expand Down

0 comments on commit f05e8f4

Please sign in to comment.