@bjj/nuxt-layer-shadcn-ui 0.12.12 → 0.12.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,7 @@
1
1
  <script setup lang="ts" generic="TValue extends string | number = string, TMeta = unknown">
2
2
  import {
3
3
  Command,
4
- CommandEmpty,
5
4
  CommandGroup,
6
- CommandInput,
7
5
  CommandItem,
8
6
  CommandList,
9
7
  CommandSeparator,
@@ -18,6 +16,7 @@ import {
18
16
  PopoverContent,
19
17
  PopoverTrigger,
20
18
  } from '../../shadcn/popover'
19
+ import { ListboxFilter } from 'reka-ui'
21
20
  import type { SelectOption, SelectProps } from './types'
22
21
 
23
22
  type Option = SelectOption<TValue, TMeta>
@@ -77,9 +76,39 @@ function handleTriggerClickCapture (event: Event) {
77
76
  }
78
77
 
79
78
  // -- Filter --
79
+ //
80
+ // We render our own ListboxFilter search box instead of shadcn's CommandInput:
81
+ // CommandInput only writes into Command's internal filterState (client-side
82
+ // filtering) and reka's ListboxRoot never emits `update:searchTerm`, so the
83
+ // typed term can't be observed for server-side search. Driving our own term
84
+ // surfaces it via `@search` and keeps filterState idle (no double filtering).
85
+ //
86
+ // `filter === true` matches option labels; a `filter` function is a custom
87
+ // matcher (server search passes `items => items` to show everything and filter
88
+ // on the server instead).
89
+
90
+ const searchTerm = ref('')
91
+
92
+ function handleSearchInput (value: string) {
93
+ searchTerm.value = value
94
+ emit('search', value)
95
+ }
80
96
 
81
- const commandFilterFunction = computed(() => {
82
- return typeof props.filter === 'function' ? props.filter : undefined
97
+ // Clear the local term when the popover closes so a reopen starts fresh.
98
+ watch(open, value => {
99
+ if (!value) searchTerm.value = ''
100
+ })
101
+
102
+ const visibleOptions = computed<Option[]>(() => {
103
+ const options = props.options ?? []
104
+ const keyword = searchTerm.value
105
+ if (!props.filter || !keyword) return options
106
+ if (typeof props.filter === 'function') {
107
+ const kept = new Set(props.filter(options.map(opt => opt.label), keyword))
108
+ return options.filter(opt => kept.has(opt.label))
109
+ }
110
+ const lower = keyword.toLowerCase()
111
+ return options.filter(opt => opt.label.toLowerCase().includes(lower))
83
112
  })
84
113
 
85
114
  // -- Selection --
@@ -126,7 +155,7 @@ const groupedOptions = computed<OptionGroupEntry[]>(() => {
126
155
  const groups: OptionGroupEntry[] = []
127
156
  const map = new Map<string | undefined, OptionGroupEntry>()
128
157
 
129
- for (const opt of props.options ?? []) {
158
+ for (const opt of visibleOptions.value) {
130
159
  const key = opt.group
131
160
  let group = map.get(key)
132
161
  if (!group) {
@@ -254,19 +283,36 @@ function handleClear (event: MouseEvent) {
254
283
  <PopoverContent class="p-0 w-(--reka-popover-trigger-width)">
255
284
  <Command
256
285
  :modelValue="commandModelValue"
257
- :filterFunction="commandFilterFunction"
258
286
  :multiple="multiple"
259
287
  highlightOnHover
260
- @update:searchTerm="(value: string) => emit('search', value)"
261
288
  >
262
- <CommandInput
289
+ <div
263
290
  v-if="!!filter"
264
- :placeholder="searchPlaceholder || T('searchPlaceholder')"
265
- />
291
+ class="gap-2 px-3 h-9 flex items-center border-b"
292
+ >
293
+ <Icon
294
+ name="search"
295
+ class="size-4 shrink-0 opacity-50"
296
+ />
297
+ <ListboxFilter
298
+ :modelValue="searchTerm"
299
+ autoFocus
300
+ :placeholder="searchPlaceholder || T('searchPlaceholder')"
301
+ class="
302
+ py-3 text-sm
303
+ placeholder:text-muted-foreground
304
+ h-10 flex w-full bg-transparent outline-hidden
305
+ "
306
+ @update:modelValue="handleSearchInput"
307
+ />
308
+ </div>
266
309
  <CommandList>
267
- <CommandEmpty>
310
+ <div
311
+ v-if="!loading && groupedOptions.length === 0"
312
+ class="py-6 text-sm text-muted-foreground text-center"
313
+ >
268
314
  {{ emptyText || T('noItems') }}
269
- </CommandEmpty>
315
+ </div>
270
316
 
271
317
  <template
272
318
  v-for="(group, index) in groupedOptions"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjj/nuxt-layer-shadcn-ui",
3
- "version": "0.12.12",
3
+ "version": "0.12.13",
4
4
  "description": "Nuxt layer providing shadcn-vue based UI components",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -42,5 +42,5 @@
42
42
  "vue-i18n": "^11",
43
43
  "vue-router": "^4 || ^5"
44
44
  },
45
- "gitHead": "d13532a40af6aab9b6d43e65cebfb5cd5dcd72bb"
45
+ "gitHead": "ac169020da6ae2c20d53c89d7c3b628f52d806c9"
46
46
  }