N
Nuxt4w ago
Viridian

<USelect> in #trailing slot in <UInput> does not appear clickable

I'm trying to make this work:
<UFormGroup :label="labels.daily" size="lg" :ui="{ label: { base: 'font-semibold text-md' } }">
<UInput
type="number"
step="0.01"
placeholder="3.14"
input-class="no-spinner"
:model-value="rateValue"
@update:model-value="updateRateValue"
icon="i-material-symbols-electric-bolt"
>
<template #trailing>
<USelect
v-model="selectedPeriod"
:options="periodOptions"
size="xs"
:ui="{ base: 'w-28' }"
/>
</template>
</UInput>
</UFormGroup>
<UFormGroup :label="labels.daily" size="lg" :ui="{ label: { base: 'font-semibold text-md' } }">
<UInput
type="number"
step="0.01"
placeholder="3.14"
input-class="no-spinner"
:model-value="rateValue"
@update:model-value="updateRateValue"
icon="i-material-symbols-electric-bolt"
>
<template #trailing>
<USelect
v-model="selectedPeriod"
:options="periodOptions"
size="xs"
:ui="{ base: 'w-28' }"
/>
</template>
</UInput>
</UFormGroup>
However, the <USelect> inside the UInput's trailing slot doesn't seem to be clickable and doesn't activate a dropdown when clicked. Instead, the click seems to propagate through to the button. I tried @click.prevent and @click.stop, but they didn't seem to work. What else am I missing?
9 Replies
kapa.ai
kapa.ai4w ago
Hi @Viridian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, I can help you with this issue. The problem you're experiencing is related to the default behavior of the UInput component's trailing slot. Here's how you can solve it: The UInput component applies a pointer-events-none class to its trailing icon wrapper by default, which prevents click events from reaching the elements inside the slot. To make the USelect in the trailing slot clickable, you need to remove this class. You can do this by adding a specific UI prop to the UInput component. Here's how you can modify your code to make the USelect clickable:
<UFormGroup :label="labels.daily" size="lg" :ui="{ label: { base: 'font-semibold text-md' } }">
<UInput
type="number"
step="0.01"
placeholder="3.14"
input-class="no-spinner"
:model-value="rateValue"
@update:model-value="updateRateValue"
icon="i-material-symbols-electric-bolt"
:ui="{ icon: { trailing: { pointer: '' } } }"
>
<template #trailing>
<USelect
v-model="selectedPeriod"
:options="periodOptions"
size="xs"
:ui="{ base: 'w-28' }"
/>
</template>
</UInput>
</UFormGroup>
<UFormGroup :label="labels.daily" size="lg" :ui="{ label: { base: 'font-semibold text-md' } }">
<UInput
type="number"
step="0.01"
placeholder="3.14"
input-class="no-spinner"
:model-value="rateValue"
@update:model-value="updateRateValue"
icon="i-material-symbols-electric-bolt"
:ui="{ icon: { trailing: { pointer: '' } } }"
>
<template #trailing>
<USelect
v-model="selectedPeriod"
:options="periodOptions"
size="xs"
:ui="{ base: 'w-28' }"
/>
</template>
</UInput>
</UFormGroup>
The key change is adding this prop to the UInput component:
:ui="{ icon: { trailing: { pointer: '' } } }"
:ui="{ icon: { trailing: { pointer: '' } } }"
This removes the pointer-events-none class from the trailing icon wrapper, allowing the USelect to receive click events. This solution is based on the information provided in the Input component documentation, which states: "As leading and trailing icons are wrapped around a pointer-events-none class, if you inject a clickable element in the slot, you need to remove this class to make it clickable by adding :ui="{ icon: { trailing: { pointer: '' } } }" to the Input." With this modification, your USelect inside the UInput's trailing slot should now be clickable and function as expected. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Viridian
ViridianOP3w ago
@kapa.ai Is there a way to make a search Input with autocomplete? What would I use?
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, there is a way to create a search input with autocomplete functionality in Nuxt UI. For this purpose, you would use the UInputMenu component. This component is specifically designed to display an autocomplete input with real-time suggestions. Here's a basic example of how you can use UInputMenu:
<script setup lang="ts">
const options = ['Wade Cooper', 'Arlene Mccoy', 'Devon Webb', 'Tom Cook', 'Tanya Fox', 'Hellen Schmidt']
const selected = ref('')
</script>

<template>
<UInputMenu v-model="selected" :options="options" placeholder="Search for a person..." />
</template>
<script setup lang="ts">
const options = ['Wade Cooper', 'Arlene Mccoy', 'Devon Webb', 'Tom Cook', 'Tanya Fox', 'Hellen Schmidt']
const selected = ref('')
</script>

<template>
<UInputMenu v-model="selected" :options="options" placeholder="Search for a person..." />
</template>
Key features of UInputMenu: 1. It renders an UInput component by default and is based on the ui.input preset. 2. You can pass an array of strings or objects to the options prop to display in the menu. 3. It supports real-time filtering of options as you type. 4. You can customize its appearance using props like color, variant, size, placeholder, icon, etc. For more advanced usage, such as working with objects, async search, or controlling the query, you can refer to the UInputMenu documentation. If you need more control over the search functionality, you might want to consider using the UCommandPalette component, which offers more advanced features for implementing full-text search. The CommandPalette documentation provides examples of how to use it with different search libraries like Fuse.js or MiniSearch. Remember, these components are part of Nuxt UI, so make sure you have it properly installed and configured in your Nuxt project before using them. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Viridian
ViridianOP3w ago
@kapa.ai How do I improve performance in my UItemInput? Can I use something like vue-virtual-scroller? Here's my code:
<UInputMenu
v-model="value"
:items="items"
placeholder="Search for resources..."
class="w-full"
size="xl"
icon="i-lucide-search"
>
<template #item-leading="{ item, index }">
<UIcon v-if="item.type === 'route'" class="text-green-500" name="i-lucide-map" />
<img v-if="item.type === 'pokemon'" :src="`https://raw.githubusercontent.com/May8th1995/sprites/master/${parseMonName(item.label)}.png`">
<UIcon v-if="item.type === 'trainer'" class="text-green-500" name="mdi-pokeball" />
</template>
</UInputMenu>
<UInputMenu
v-model="value"
:items="items"
placeholder="Search for resources..."
class="w-full"
size="xl"
icon="i-lucide-search"
>
<template #item-leading="{ item, index }">
<UIcon v-if="item.type === 'route'" class="text-green-500" name="i-lucide-map" />
<img v-if="item.type === 'pokemon'" :src="`https://raw.githubusercontent.com/May8th1995/sprites/master/${parseMonName(item.label)}.png`">
<UIcon v-if="item.type === 'trainer'" class="text-green-500" name="mdi-pokeball" />
</template>
</UInputMenu>
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the knowledge sources provided, I don't have specific information about using vue-virtual-scroller with UInputMenu or improving its performance directly. However, I can provide some insights based on the available information about the UInputMenu component in Nuxt UI. The UInputMenu component is designed to display an autocomplete input with real-time suggestions. It doesn't have built-in virtualization for large lists of items. If you're experiencing performance issues with a large number of items, you might consider the following approaches: 1. Async Search: Instead of loading all items at once, you can use the async search feature of UInputMenu. This allows you to load items as the user types, which can significantly improve performance for large datasets. Here's how you can implement it:
<script setup lang="ts">
const loading = ref(false)
const selected = ref()

async function search(q: string) {
loading.value = true
// Implement your search logic here, fetching only the necessary items
const searchedItems = await fetchItems(q)
loading.value = false
return searchedItems
}
</script>

<template>
<UInputMenu
v-model="selected"
:search="search"
:loading="loading"
placeholder="Search for resources..."
class="w-full"
size="xl"
icon="i-lucide-search"
>
<template #item-leading="{ item }">
<!-- Your existing template code -->
</template>
</UInputMenu>
</template>
<script setup lang="ts">
const loading = ref(false)
const selected = ref()

async function search(q: string) {
loading.value = true
// Implement your search logic here, fetching only the necessary items
const searchedItems = await fetchItems(q)
loading.value = false
return searchedItems
}
</script>

<template>
<UInputMenu
v-model="selected"
:search="search"
:loading="loading"
placeholder="Search for resources..."
class="w-full"
size="xl"
icon="i-lucide-search"
>
<template #item-leading="{ item }">
<!-- Your existing template code -->
</template>
</UInputMenu>
</template>
This approach is documented in the InputMenu Async search section. 2. Limit the number of displayed items: If you're not already doing so, consider limiting the number of items displayed in the dropdown at any given time. This can be done on the server-side or client-side, depending on your setup. 3. Debounce the search: To reduce the number of search operations, you can use the debounce prop:
<UInputMenu
v-model="selected"
:search="search"
:loading="loading"
:debounce="300"
placeholder="Search for resources..."
class="w-full"
size="xl"
icon="i-lucide-search"
>
<!-- ... -->
</UInputMenu>
<UInputMenu
v-model="selected"
:search="search"
:loading="loading"
:debounce="300"
placeholder="Search for resources..."
class="w-full"
size="xl"
icon="i-lucide-search"
>
<!-- ... -->
</UInputMenu>
This will delay the search execution until the user has stopped typing for 300 milliseconds. As for using vue-virtual-scroller, while it's a great tool for virtualizing large lists, it's not directly compatible with UInputMenu based on the provided documentation. Implementing it would require significant customization of the UInputMenu component, which is beyond the scope of the standard usage. If these optimizations don't suffice and you need more advanced virtualization, you might need to consider creating a custom component that combines the functionality of UInputMenu with a virtualized list. However, this would be a complex task and is not covered in the provided Nuxt UI documentation. InputMenu documentation provides more details on the available props and customization options that might help you optimize your specific use case. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Wm
Wm3w ago
What is the desired result? It is unclear to me what the goal is. Why is a USelect being put into a UInput?

Did you find this page helpful?