feat(SelectMenu): add prop to disable search

This commit is contained in:
Benjamin Canac
2024-07-10 12:56:38 +02:00
parent 781047eacb
commit db30284e7a
3 changed files with 502 additions and 445 deletions

View File

@@ -30,6 +30,11 @@ export interface SelectMenuProps<T> extends Pick<ComboboxRootProps<T>, 'modelVal
id?: string
/** The placeholder text when the select is empty. */
placeholder?: string
/**
* Wether to display the search input or not.
* @defaultValue true
*/
search?: boolean
/** The placeholder text when the search input is empty. */
searchPlaceholder?: string
color?: SelectMenuVariants['color']
@@ -109,6 +114,7 @@ import { UIcon, UChip, UAvatar } from '#components'
import { get } from '../utils'
const props = withDefaults(defineProps<SelectMenuProps<T>>(), {
search: true,
portal: true,
autofocusDelay: 0,
searchPlaceholder: 'Search...',
@@ -234,7 +240,7 @@ function onUpdateOpen(value: boolean) {
<ComboboxPortal :disabled="!portal">
<ComboboxContent :class="ui.content({ class: props.ui?.content })" v-bind="contentProps">
<ComboboxInput :placeholder="searchPlaceholder" :class="ui.input({ class: props.ui?.input })" autofocus autocomplete="off" />
<ComboboxInput v-if="search" :placeholder="searchPlaceholder" :class="ui.input({ class: props.ui?.input })" autofocus autocomplete="off" />
<ComboboxEmpty :class="ui.empty({ class: props.ui?.empty })">
<slot name="empty" :search-term="searchTerm">

View File

@@ -45,6 +45,7 @@ describe('SelectMenu', () => {
['with name', { props: { ...props, name: 'name' } }],
['with placeholder', { props: { ...props, placeholder: 'Search...' } }],
['with searchPlaceholder', { props: { ...props, searchPlaceholder: 'Filter items...' } }],
['without search', { props: { ...props, search: false } }],
['with disabled', { props: { ...props, disabled: true } }],
['with required', { props: { ...props, required: true } }],
['with icon', { props: { ...props, icon: 'i-heroicons-magnifying-glass' } }],

File diff suppressed because it is too large Load Diff