Skip to content

Commit edda8a6

Browse files
feat(CommandPalette)!: add children-icon prop to use trailing-icon in input (#4397)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
1 parent 38647a2 commit edda8a6

File tree

4 files changed

+191
-2
lines changed

4 files changed

+191
-2
lines changed

src/runtime/components/CommandPalette.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export interface CommandPaletteProps<G extends CommandPaletteGroup<T> = CommandP
7171
* @IconifyIcon
7272
*/
7373
icon?: IconProps['name']
74+
/**
75+
* The icon displayed on the right side of the input.
76+
* @defaultValue appConfig.ui.icons.search
77+
* @IconifyIcon
78+
*/
79+
trailingIcon?: IconProps['name']
7480
/**
7581
* The icon displayed when an item is selected.
7682
* @defaultValue appConfig.ui.icons.check
@@ -82,7 +88,7 @@ export interface CommandPaletteProps<G extends CommandPaletteGroup<T> = CommandP
8288
* @defaultValue appConfig.ui.icons.chevronRight
8389
* @IconifyIcon
8490
*/
85-
trailingIcon?: IconProps['name']
91+
childrenIcon?: IconProps['name']
8692
/**
8793
* The placeholder text for the input.
8894
* @defaultValue t('commandPalette.placeholder')
@@ -450,7 +456,7 @@ function onSelect(e: Event, item: T) {
450456
<slot :name="((item.slot ? `${item.slot}-trailing` : group?.slot ? `${group.slot}-trailing` : `item-trailing`) as keyof CommandPaletteSlots<G, T>)" :item="(item as any)" :index="index" :ui="ui">
451457
<UIcon
452458
v-if="item.children && item.children.length > 0"
453-
:name="trailingIcon || appConfig.ui.icons.chevronRight"
459+
:name="childrenIcon || appConfig.ui.icons.chevronRight"
454460
:class="ui.itemTrailingIcon({ class: [props.ui?.itemTrailingIcon, item.ui?.itemTrailingIcon] })"
455461
/>
456462

@@ -479,6 +485,7 @@ function onSelect(e: Event, item: T) {
479485
:autofocus="autofocus"
480486
v-bind="inputProps"
481487
:loading-icon="loadingIcon"
488+
:trailing-icon="trailingIcon"
482489
:icon="icon || appConfig.ui.icons.search"
483490
:class="ui.input({ class: props.ui?.input })"
484491
@keydown.backspace="onBackspace"

test/components/CommandPalette.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ describe('CommandPalette', () => {
113113
['with placeholder', { props: { ...props, placeholder: 'Search...' } }],
114114
['with disabled', { props: { ...props, disabled: true } }],
115115
['with icon', { props: { ...props, icon: 'i-lucide-terminal' } }],
116+
['with trailingIcon', { props: { ...props, trailingIcon: 'i-lucide-settings' } }],
117+
['with childrenIcon', { props: { ...props, childrenIcon: 'i-lucide-arrow-right' } }],
116118
['with loading', { props: { ...props, loading: true } }],
117119
['with loadingIcon', { props: { ...props, loading: true, loadingIcon: 'i-lucide-loader' } }],
118120
['with selectedIcon', { props: { ...props, selectedIcon: 'i-lucide-badge-check', modelValue: groups[2]?.items[0] } }],

0 commit comments

Comments
 (0)