Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CommandPalette): add autofocus prop #2942

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/runtime/components/CommandPalette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export interface CommandPaletteProps<G, T> extends Pick<ListboxRootProps, 'multi
* @defaultValue 'Type a command or search...'
*/
placeholder?: InputProps['placeholder']
/**
* Automatically focus the input when component is mounted.
* @defaultValue true
*/
autofocus?: boolean
/**
* Display a close button in the input (useful when inside a Modal for example).
* `{ size: 'md', color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
Expand Down Expand Up @@ -141,7 +146,8 @@ import UInput from './Input.vue'
const props = withDefaults(defineProps<CommandPaletteProps<G, T>>(), {
modelValue: '',
placeholder: 'Type a command or search...',
labelKey: 'label'
labelKey: 'label',
autofocus: true
})
const emits = defineEmits<CommandPaletteEmits<T>>()
const slots = defineSlots<CommandPaletteSlots<G, T>>()
Expand Down Expand Up @@ -239,7 +245,7 @@ const groups = computed(() => {
<ListboxFilter v-model="searchTerm" as-child>
<UInput
variant="none"
autofocus
:autofocus="autofocus"
size="lg"
v-bind="inputProps"
:icon="icon || appConfig.ui.icons.search"
Expand Down
Loading