Skip to content

Commit

Permalink
fix(VCombobox): don't delete chips on backspace until search is empty
Browse files Browse the repository at this point in the history
fixes #19626
  • Loading branch information
KaelWD committed Apr 17, 2024
1 parent c1e8150 commit d6a500b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
21 changes: 9 additions & 12 deletions packages/vuetify/src/components/VAutocomplete/VAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,18 @@ export const VAutocomplete = genericComponent<new <
if (
!props.multiple &&
hasSelectionSlot.value &&
model.value.length > 0
model.value.length > 0 &&
!search.value
) return select(model.value[0], false)

if (selectionIndex.value < 0) {
if (e.key === 'Backspace' && !search.value) {
selectionIndex.value = length - 1
}
if (~selectionIndex.value) {
const originalSelectionIndex = selectionIndex.value
select(model.value[selectionIndex.value], false)

return
selectionIndex.value = originalSelectionIndex >= length - 1 ? (length - 2) : originalSelectionIndex
} else if (e.key === 'Backspace' && !search.value) {
selectionIndex.value = length - 1
}

const originalSelectionIndex = selectionIndex.value
select(model.value[selectionIndex.value], false)

selectionIndex.value = originalSelectionIndex >= length - 1 ? (length - 2) : originalSelectionIndex
}

if (!props.multiple) return
Expand Down Expand Up @@ -324,7 +321,7 @@ export const VAutocomplete = genericComponent<new <
listHasFocus.value = false
}
function onUpdateModelValue (v: any) {
if (v == null || (v === '' && !props.multiple)) model.value = []
if (v == null || (v === '' && !props.multiple && !hasSelectionSlot.value)) model.value = []
}

const isSelecting = shallowRef(false)
Expand Down
22 changes: 10 additions & 12 deletions packages/vuetify/src/components/VCombobox/VCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,18 @@ export const VCombobox = genericComponent<new <
if (
!props.multiple &&
hasSelectionSlot.value &&
model.value.length > 0
model.value.length > 0 &&
!search.value
) return select(model.value[0], false)

if (selectionIndex.value < 0) {
if (e.key === 'Backspace' && !search.value) {
selectionIndex.value = length - 1
}
return
}
if (~selectionIndex.value) {
const originalSelectionIndex = selectionIndex.value
select(model.value[selectionIndex.value], false)

const originalSelectionIndex = selectionIndex.value
select(model.value[selectionIndex.value], false)

selectionIndex.value = originalSelectionIndex >= length - 1 ? (length - 2) : originalSelectionIndex
selectionIndex.value = originalSelectionIndex >= length - 1 ? (length - 2) : originalSelectionIndex
} else if (e.key === 'Backspace' && !search.value) {
selectionIndex.value = length - 1
}
}

if (!props.multiple) return
Expand Down Expand Up @@ -405,7 +403,7 @@ export const VCombobox = genericComponent<new <
listHasFocus.value = false
}
function onUpdateModelValue (v: any) {
if (v == null || (v === '' && !props.multiple)) model.value = []
if (v == null || (v === '' && !props.multiple && !hasSelectionSlot.value)) model.value = []
}

watch(isFocused, (val, oldVal) => {
Expand Down

0 comments on commit d6a500b

Please sign in to comment.