LCOV - code coverage report
Current view: top level - packages/design-system/src/components/single-select - SearchableSingleSelect.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 90.9 % 22 20
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1           16 : <template>
       2          162 :   <ComboboxRoot
       3              :     v-model="selectedOption"
       4              :     v-model:open="isOpen"
       5              :     by="value"
       6              :     :disabled
       7              :     ignore-filter
       8              :   >
       9              :     <ComboboxAnchor as-child>
      10              :       <ComboboxTrigger
      11              :         ref="trigger"
      12              :         v-bind="attrsWithoutClass"
      13              :         tabindex="0"
      14              :         :aria-label="accessibleLabel"
      15              :         :aria-busy="loading || undefined"
      16              :         :aria-invalid="invalid || undefined"
      17              :         :class="
      18              :           cn(
      19              :             selectTriggerVariants({
      20              :               size,
      21              :               border: invalid ? 'invalid' : 'none'
      22              :             }),
      23              :             attrsClass
      24              :           )
      25              :         "
      26              :       >
      27              :         <div
      28              :           :class="
      29              :             cn(
      30              :               'flex flex-1 items-center gap-2 overflow-hidden py-2 pl-2',
      31              :               size === 'md' ? 'text-xs' : 'text-sm'
      32              :             )
      33              :           "
      34              :         >
      35              :           <i
      36              :             v-if="loading"
      37              :             class="icon-[lucide--loader-circle] animate-spin text-muted-foreground"
      38              :           />
      39              :           <slot v-else name="icon" />
      40              :           <span class="truncate">{{ selectedOption?.name ?? label }}</span>
      41              :         </div>
      42              :         <div :class="selectDropdownClass">
      43              :           <i class="icon-[lucide--chevron-down] text-muted-foreground" />
      44              :         </div>
      45              :       </ComboboxTrigger>
      46              :     </ComboboxAnchor>
      47              : 
      48              :     <ComboboxPortal :key="Number(isOpen)">
      49              :       <ComboboxContent
      50              :         position="popper"
      51              :         :side-offset="8"
      52              :         align="start"
      53              :         :style="[optionStyle, contentStyle]"
      54              :         :class="cn(selectContentClass, 'min-w-(--reka-combobox-trigger-width)')"
      55              :         @keydown="onContentKeydown"
      56              :       >
      57              :         <FocusScope
      58              :           class="contents"
      59              :           @mount-auto-focus.prevent
      60              :           @unmount-auto-focus.prevent
      61              :         >
      62              :           <div class="px-2 pt-2">
      63              :             <div class="flex items-center gap-2 rounded-lg border px-3 py-1.5">
      64              :               <i class="icon-[lucide--search] text-muted-foreground" />
      65              :               <ComboboxInput
      66              :                 v-model="searchQuery"
      67              :                 :aria-label="searchLabel"
      68              :                 :placeholder="searchPlaceholder"
      69              :                 class="w-full border-none bg-transparent text-sm outline-none"
      70              :               />
      71              :             </div>
      72              :           </div>
      73              :           <ComboboxViewport
      74              :             :style="{ maxHeight: `min(${listMaxHeight}, 50vh)` }"
      75              :             class="scrollbar-custom w-full"
      76              :           >
      77        10144 :             <ComboboxItem
      78              :               v-for="opt in filteredOptions"
      79              :               :key="opt.value"
      80              :               :value="opt"
      81              :               :class="selectItemVariants({ layout: 'single' })"
      82              :             >
      83              :               <span class="truncate">{{ opt.name }}</span>
      84              :               <ComboboxItemIndicator
      85              :                 class="flex shrink-0 items-center justify-center"
      86              :               >
      87              :                 <i
      88              :                   class="icon-[lucide--check] text-foreground"
      89              :                   aria-hidden="true"
      90              :                 />
      91              :               </ComboboxItemIndicator>
      92              :             </ComboboxItem>
      93              :             <ComboboxEmpty :class="selectEmptyMessageClass">
      94              :               {{ emptyText }}
      95              :             </ComboboxEmpty>
      96              :           </ComboboxViewport>
      97              :         </FocusScope>
      98              :       </ComboboxContent>
      99              :     </ComboboxPortal>
     100              :   </ComboboxRoot>
     101              : </template>
     102              : 
     103              : <script setup lang="ts">
     104              : import { cn } from '@comfyorg/tailwind-utils'
     105              : import { unrefElement } from '@vueuse/core'
     106              : import {
     107              :   ComboboxAnchor,
     108              :   ComboboxContent,
     109              :   ComboboxEmpty,
     110              :   ComboboxInput,
     111              :   ComboboxItem,
     112              :   ComboboxItemIndicator,
     113              :   ComboboxRoot,
     114              :   ComboboxTrigger,
     115              :   ComboboxViewport,
     116              :   FocusScope,
     117              :   ComboboxPortal
     118              : } from 'reka-ui'
     119              : import { computed, ref, useTemplateRef, watch } from 'vue'
     120              : import type { StyleValue } from 'vue'
     121              : 
     122              : import {
     123              :   selectContentClass,
     124              :   selectDropdownClass,
     125              :   selectEmptyMessageClass,
     126              :   selectItemVariants,
     127              :   selectTriggerVariants,
     128              :   stopEscapeToDocument
     129              : } from '@comfyorg/design-system/select.variants'
     130              : import type { SelectOption } from '@comfyorg/design-system/lib/select/types'
     131              : import { useSelectSearch } from '@comfyorg/design-system/lib/select/useSelectSearch'
     132              : import { useAttrsClass } from '@comfyorg/design-system/lib/composables/useAttrsClass'
     133              : import { usePopoverSizing } from '@comfyorg/design-system/lib/composables/usePopoverSizing'
     134              : 
     135              : defineOptions({ inheritAttrs: false })
     136              : 
     137           23 : const { attrsClass, attrsWithoutClass } = useAttrsClass()
     138              : const {
     139              :   label,
     140              :   accessibleLabel,
     141              :   searchLabel,
     142              :   emptyText,
     143              :   options = [],
     144              :   size = 'lg',
     145              :   invalid = false,
     146              :   loading = false,
     147              :   disabled = false,
     148              :   searchPlaceholder,
     149              :   listMaxHeight = '28rem',
     150              :   popoverMinWidth,
     151              :   popoverMaxWidth,
     152              :   contentStyle
     153              : } = defineProps<{
     154              :   label?: string
     155              :   accessibleLabel: string
     156              :   searchLabel: string
     157              :   emptyText: string
     158              :   options?: SelectOption<string | number>[]
     159              :   size?: 'lg' | 'md'
     160              :   invalid?: boolean
     161              :   loading?: boolean
     162              :   disabled?: boolean
     163              :   searchPlaceholder?: string
     164              :   listMaxHeight?: string
     165              :   popoverMinWidth?: string
     166              :   popoverMaxWidth?: string
     167              :   contentStyle?: StyleValue
     168              : }>()
     169              : 
     170           23 : const selectedItem = defineModel<string | number | undefined>({
     171              :   required: true
     172              : })
     173           23 : const triggerRef = useTemplateRef('trigger')
     174           23 : const isOpen = ref(false)
     175           23 : const searchQuery = ref('')
     176           23 : const filteredOptions = useSelectSearch(searchQuery, () => options)
     177           23 : const selectedOption = computed({
     178              :   get: () => options.find(({ value }) => value === selectedItem.value),
     179              :   set: (option: SelectOption<string | number> | undefined) => {
     180           17 :     selectedItem.value = option?.value
     181              :   }
     182              : })
     183              : 
     184           23 : watch(isOpen, (open) => {
     185           38 :   if (!open) searchQuery.value = ''
     186              : })
     187              : 
     188            3 : function onContentKeydown(event: KeyboardEvent) {
     189            3 :   if (event.key === 'Tab') {
     190            2 :     unrefElement(triggerRef)?.focus()
     191            2 :     isOpen.value = false
     192            2 :     return
     193              :   }
     194            2 :   if (event.key === 'Escape') {
     195            0 :     stopEscapeToDocument(event)
     196            0 :     isOpen.value = false
     197              :   }
     198              : }
     199              : 
     200           23 : const optionStyle = usePopoverSizing({
     201              :   minWidth: popoverMinWidth,
     202              :   maxWidth: popoverMaxWidth
     203              : })
     204              : </script>
        

Generated by: LCOV version 2.0-1