Skip to content

Commit

Permalink
fix(InputMenu): emit focus event (#2386)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <[email protected]>
  • Loading branch information
tomykho and benjamincanac authored Oct 18, 2024
1 parent f59844b commit 7802aac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
const open = ref(false)
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const selected = ref('Backlog')
</script>

<template>
<UInputMenu
v-model="selected"
v-model:open="open"
:items="items"
@focus="open = true"
/>
</template>
10 changes: 10 additions & 0 deletions docs/content/3.components/input-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ name: 'input-menu-open-example'
In this example, press :kbd{value="O"} to toggle the InputMenu.
::

### Control open state on focus

You can also use the `@focus` directive to control the open state.

::component-example
---
name: 'input-menu-open-focus-example'
---
::

### Control search term

Use the `v-model:search-term` directive to control the search term.
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/components/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ function onBlur(event: FocusEvent) {
emitFormBlur()
}
function onFocus(event: FocusEvent) {
emits('focus', event)
}
function onUpdateOpen(value: boolean) {
if (!value) {
const event = new FocusEvent('blur')
Expand Down Expand Up @@ -269,6 +273,7 @@ defineExpose({
delimiter=""
as-child
@blur="onBlur"
@focus="onFocus"
>
<TagsInputItem v-for="(item, index) in tags" :key="index" :value="(item as string)" :class="ui.tagsItem({ class: props.ui?.tagsItem })">
<TagsInputItemText :class="ui.tagsItemText({ class: props.ui?.tagsItemText })">
Expand Down Expand Up @@ -305,6 +310,7 @@ defineExpose({
:required="required"
:class="ui.base({ class: props.ui?.base })"
@blur="onBlur"
@focus="onFocus"
/>

<span v-if="isLeading || !!avatar || !!slots.leading" :class="ui.leading({ class: props.ui?.leading })">
Expand Down

0 comments on commit 7802aac

Please sign in to comment.