mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
feat(InputMenu): expose modelValue and open to slots
This commit is contained in:
@@ -50,7 +50,11 @@ const { data: users, pending } = await useFetch('https://jsonplaceholder.typicod
|
||||
<UInputMenu :items="items" placeholder="Required" required />
|
||||
<UInputMenu :items="items" loading placeholder="Search..." />
|
||||
<UInputMenu :items="items" loading leading-icon="i-heroicons-magnifying-glass" placeholder="Search..." />
|
||||
<UInputMenu :items="statuses" placeholder="Search status..." icon="i-heroicons-magnifying-glass" trailing-icon="i-heroicons-chevron-up-down-20-solid" />
|
||||
<UInputMenu :items="statuses" placeholder="Search status..." icon="i-heroicons-magnifying-glass" trailing-icon="i-heroicons-chevron-up-down-20-solid">
|
||||
<template #leading="{ modelValue }">
|
||||
<UIcon v-if="modelValue" :name="modelValue.icon" class="size-5" />
|
||||
</template>
|
||||
</UInputMenu>
|
||||
<UInputMenu
|
||||
v-model:search-term="searchTerm"
|
||||
:items="users || []"
|
||||
@@ -59,7 +63,11 @@ const { data: users, pending } = await useFetch('https://jsonplaceholder.typicod
|
||||
icon="i-heroicons-user"
|
||||
placeholder="Search users..."
|
||||
@update:open="searchTerm = ''"
|
||||
/>
|
||||
>
|
||||
<template #leading="{ modelValue }">
|
||||
<UAvatar v-if="modelValue?.avatar" size="2xs" v-bind="modelValue.avatar" />
|
||||
</template>
|
||||
</UInputMenu>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<UInputMenu
|
||||
|
||||
@@ -27,7 +27,7 @@ export interface InputMenuItem extends Pick<ComboboxItemProps, 'disabled'> {
|
||||
|
||||
type InputMenuVariants = VariantProps<typeof inputMenu>
|
||||
|
||||
export interface InputMenuProps<T> extends Omit<ComboboxRootProps, 'asChild' | 'dir' | 'filterFunction' | 'displayValue' | 'multiple'>, UseComponentIconsProps {
|
||||
export interface InputMenuProps<T> extends Omit<ComboboxRootProps<T>, 'asChild' | 'dir' | 'filterFunction' | 'displayValue' | 'multiple'>, UseComponentIconsProps {
|
||||
id?: string
|
||||
type?: InputHTMLAttributes['type']
|
||||
/** The placeholder text when the input is empty. */
|
||||
@@ -67,9 +67,8 @@ export type InputMenuEmits<T> = ComboboxRootEmits<T>
|
||||
type SlotProps<T> = (props: { item: T, index: number }) => any
|
||||
|
||||
export type InputMenuSlots<T> = {
|
||||
'leading'(): any
|
||||
'default'(): any
|
||||
'trailing'(): any
|
||||
'leading'(props: { modelValue: T, open: boolean }): any
|
||||
'trailing'(props: { modelValue: T, open: boolean }): any
|
||||
'empty'(props: { searchTerm?: string }): any
|
||||
'item': SlotProps<T>
|
||||
'item-leading': SlotProps<T>
|
||||
@@ -165,6 +164,7 @@ onMounted(() => {
|
||||
<template>
|
||||
<ComboboxRoot
|
||||
:id="id"
|
||||
v-slot="{ modelValue, open }"
|
||||
:name="name"
|
||||
:disabled="disabled"
|
||||
v-bind="rootProps"
|
||||
@@ -186,13 +186,13 @@ onMounted(() => {
|
||||
/>
|
||||
|
||||
<span v-if="isLeading || !!slots.leading" :class="ui.leading()">
|
||||
<slot name="leading">
|
||||
<slot name="leading" :model-value="(modelValue as T)" :open="open">
|
||||
<UIcon v-if="leadingIconName" :name="leadingIconName" :class="ui.leadingIcon()" />
|
||||
</slot>
|
||||
</span>
|
||||
|
||||
<ComboboxTrigger v-if="isTrailing || !!slots.trailing" :class="ui.trailing()">
|
||||
<slot name="trailing">
|
||||
<slot name="trailing" :model-value="(modelValue as T)" :open="open">
|
||||
<UIcon v-if="trailingIconName" :name="trailingIconName" :class="ui.trailingIcon()" />
|
||||
</slot>
|
||||
</ComboboxTrigger>
|
||||
|
||||
Reference in New Issue
Block a user