Skip to content

Commit f97df64

Browse files
shweta2101cyrossignol
authored andcommitted
Simplify close handlers using nullish coalescing
Replace duplicated conditional logic in onKeydown and handleClickOutside with optional chaining and nullish coalescing. Compute name = pg?.name ?? selectedGroupName.value, assign it to searchText, and only update selectedGroupName when a matching project group exists. This makes the code more concise and preserves the previously selected group name instead of clearing searchText when no matching group is found.
1 parent 2440434 commit f97df64

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

components/ProjectGroupPicker.vue

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,9 @@ const onKeydown = (e: KeyboardEvent) => {
242242
e.preventDefault()
243243
isOpen.value = false
244244
const pg = projectGroups.value.find(p => p.id === model.value)
245-
if (pg) {
246-
searchText.value = pg.name
247-
selectedGroupName.value = pg.name
248-
} else {
249-
searchText.value = ''
250-
}
245+
const name = pg?.name ?? selectedGroupName.value
246+
searchText.value = name
247+
if (pg) selectedGroupName.value = name
251248
}
252249
}
253250
@@ -256,12 +253,9 @@ const handleClickOutside = (event: MouseEvent) => {
256253
if (isOpen.value) {
257254
isOpen.value = false
258255
const pg = projectGroups.value.find(p => p.id === model.value)
259-
if (pg) {
260-
searchText.value = pg.name
261-
selectedGroupName.value = pg.name
262-
} else {
263-
searchText.value = ''
264-
}
256+
const name = pg?.name ?? selectedGroupName.value
257+
searchText.value = name
258+
if (pg) selectedGroupName.value = name
265259
}
266260
}
267261
}

0 commit comments

Comments
 (0)