diff --git a/docs/content/3.components/select-menu.md b/docs/content/3.components/select-menu.md index d1abded7..5d53dc4a 100644 --- a/docs/content/3.components/select-menu.md +++ b/docs/content/3.components/select-menu.md @@ -200,7 +200,9 @@ props: ### Search Input -Use the `search-input` prop to customize the search input. Defaults to `{ placeholder: 'Search...' }`{lang="ts-type"}. +Use the `search-input` prop to customize or hide the search input (with `false` value). + +You can pass all the props of the [Input](/components/input) component to customize it. ::component-code --- @@ -219,6 +221,7 @@ props: icon: 'i-lucide-circle-help' searchInput: placeholder: 'Filter...' + icon: 'i-lucide-search' items: - label: Backlog icon: 'i-lucide-circle-help' @@ -232,10 +235,6 @@ props: --- :: -::tip -You can set the `search-input` prop to `false` to hide the search input. -:: - ### Content Use the `content` prop to control how the SelectMenu content is rendered, like its `align` or `side` for example. diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index 1909db6b..be0a502a 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -36,9 +36,10 @@ export interface SelectMenuProps, I extends M /** * Wether to display the search input or not. * Can be an object to pass additional props to the input. - * @defaultValue { placeholder: 'Search...' } + * `{ placeholder: 'Search...', variant: 'none' }`{lang="ts-type"} + * @defaultValue true */ - searchInput?: boolean | { placeholder?: string } + searchInput?: boolean | InputProps color?: SelectMenuVariants['color'] variant?: SelectMenuVariants['variant'] size?: SelectMenuVariants['size'] @@ -131,12 +132,13 @@ import { get, escapeRegExp } from '../utils' import UIcon from './Icon.vue' import UAvatar from './Avatar.vue' import UChip from './Chip.vue' +import UInput from './Input.vue' const props = withDefaults(defineProps>(), { search: true, portal: true, autofocusDelay: 0, - searchInput: () => ({ placeholder: 'Search...' }), + searchInput: true, filter: () => ['label'], labelKey: 'label' as never }) @@ -152,6 +154,7 @@ const { t } = useLocale() const rootProps = useForwardPropsEmits(reactivePick(props, 'modelValue', 'defaultValue', 'selectedValue', 'open', 'defaultOpen', 'resetSearchTermOnBlur'), emits) const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, position: 'popper' }) as ComboboxContentProps) const arrowProps = toRef(() => props.arrow as ComboboxArrowProps) +const searchInputProps = toRef(() => defu(props.searchInput, { placeholder: 'Search...', variant: 'none' }) as InputProps) // This is a hack due to generic boolean casting (see https://github.com/nuxt/ui/issues/2541) const multiple = toRef(() => typeof props.multiple === 'string' ? true : props.multiple) @@ -276,13 +279,9 @@ function onUpdateOpen(value: boolean) { - + + + diff --git a/src/theme/select-menu.ts b/src/theme/select-menu.ts index e139e67c..a7842c6e 100644 --- a/src/theme/select-menu.ts +++ b/src/theme/select-menu.ts @@ -7,26 +7,7 @@ export default (options: Required) => { slots: { value: 'truncate', placeholder: 'truncate text-[var(--ui-text-dimmed)]', - input: 'placeholder:text-[var(--ui-text-dimmed)] border-0 border-b border-[var(--ui-border)] focus:outline-none' - }, - variants: { - size: { - xs: { - input: 'text-xs px-2 py-1' - }, - sm: { - input: 'text-xs px-2.5 py-1.5' - }, - md: { - input: 'text-sm px-2.5 py-1.5' - }, - lg: { - input: 'text-sm px-3 py-2' - }, - xl: { - input: 'text-base px-3 py-2' - } - } + input: 'border-b border-[var(--ui-border)]' } }, select(options)) } diff --git a/test/components/SelectMenu.spec.ts b/test/components/SelectMenu.spec.ts index 6af288c8..cb2b3bb1 100644 --- a/test/components/SelectMenu.spec.ts +++ b/test/components/SelectMenu.spec.ts @@ -49,6 +49,7 @@ describe('SelectMenu', () => { ['with placeholder', { props: { ...props, placeholder: 'Search...' } }], ['without searchInput', { props: { ...props, searchInput: false } }], ['with searchInput placeholder', { props: { ...props, searchInput: { placeholder: 'Filter items...' } } }], + ['with searchInput icon', { props: { ...props, searchInput: { icon: 'i-lucide-search' } } }], ['with disabled', { props: { ...props, disabled: true } }], ['with required', { props: { ...props, required: true } }], ['with icon', { props: { icon: 'i-lucide-search' } }], diff --git a/test/components/__snapshots__/SelectMenu-vue.spec.ts.snap b/test/components/__snapshots__/SelectMenu-vue.spec.ts.snap index d7dca65e..c1905491 100644 --- a/test/components/__snapshots__/SelectMenu-vue.spec.ts.snap +++ b/test/components/__snapshots__/SelectMenu-vue.spec.ts.snap @@ -8,7 +8,11 @@ exports[`SelectMenu > renders with arrow correctly 1`] = `
-
+
+
+ + +