Skip to content

Commit 1b3c919

Browse files
authoredDec 20, 2024··
feat(CommandPalette): add autofocus prop (#2942)
1 parent 0f37aca commit 1b3c919

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎src/runtime/components/CommandPalette.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export interface CommandPaletteProps<G, T> extends Pick<ListboxRootProps, 'multi
6868
* @defaultValue 'Type a command or search...'
6969
*/
7070
placeholder?: InputProps['placeholder']
71+
/**
72+
* Automatically focus the input when component is mounted.
73+
* @defaultValue true
74+
*/
75+
autofocus?: boolean
7176
/**
7277
* Display a close button in the input (useful when inside a Modal for example).
7378
* `{ size: 'md', color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
@@ -141,7 +146,8 @@ import UInput from './Input.vue'
141146
const props = withDefaults(defineProps<CommandPaletteProps<G, T>>(), {
142147
modelValue: '',
143148
placeholder: 'Type a command or search...',
144-
labelKey: 'label'
149+
labelKey: 'label',
150+
autofocus: true
145151
})
146152
const emits = defineEmits<CommandPaletteEmits<T>>()
147153
const slots = defineSlots<CommandPaletteSlots<G, T>>()
@@ -239,7 +245,7 @@ const groups = computed(() => {
239245
<ListboxFilter v-model="searchTerm" as-child>
240246
<UInput
241247
variant="none"
242-
autofocus
248+
:autofocus="autofocus"
243249
size="lg"
244250
v-bind="inputProps"
245251
:icon="icon || appConfig.ui.icons.search"

0 commit comments

Comments
 (0)
Please sign in to comment.