Skip to content

Commit

Permalink
fix(VSelect): closing chip removes selection (#19242)
Browse files Browse the repository at this point in the history
fixes #19235

Co-authored-by: John Leider <john@vuetifyjs.com>
  • Loading branch information
yuwu9145 and johnleider committed Feb 21, 2024
1 parent 22aff0a commit b5c7660
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions packages/vuetify/src/components/VAutocomplete/VAutocomplete.tsx
Expand Up @@ -322,13 +322,14 @@ export const VAutocomplete = genericComponent<new <

const isSelecting = shallowRef(false)

function select (item: ListItem, add = true) {
function select (item: ListItem) {
if (item.props.disabled) return

if (props.multiple) {
const index = model.value.findIndex(selection => props.valueComparator(selection.value, item.value))
const index = model.value.findIndex(selection => props.valueComparator(selection.value, item.value))
const add = index === -1

if (index === -1) {
if (props.multiple) {
if (add) {
model.value = [...model.value, item]
} else {
const value = [...model.value]
Expand Down Expand Up @@ -544,7 +545,7 @@ export const VAutocomplete = genericComponent<new <
e.stopPropagation()
e.preventDefault()

select(item, false)
select(item)
}

const slotProps = {
Expand Down
9 changes: 5 additions & 4 deletions packages/vuetify/src/components/VSelect/VSelect.tsx
Expand Up @@ -253,18 +253,19 @@ export const VSelect = genericComponent<new <
}
}
function select (item: ListItem) {
if (props.multiple) {
const index = model.value.findIndex(selection => props.valueComparator(selection.value, item.value))
const index = model.value.findIndex(selection => props.valueComparator(selection.value, item.value))
const add = index === -1

if (index === -1) {
if (props.multiple) {
if (add) {
model.value = [...model.value, item]
} else {
const value = [...model.value]
value.splice(index, 1)
model.value = value
}
} else {
model.value = [item]
model.value = add ? [item] : []
menu.value = false
}
}
Expand Down

0 comments on commit b5c7660

Please sign in to comment.