Skip to content

Commit 1f8b27e

Browse files
committed
fix: input not correctly re-emits events it also listens to
1 parent ef3dc13 commit 1f8b27e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/components/LibInput/LibInput.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
v-bind="inputProps"
9090
/>
9191
</slot>
92-
<slot name="indicator px-0" v-bind="{isOpen, suggestionsIndicatorClickHandler }">
92+
<slot name="indicator" v-bind="{isOpen, suggestionsIndicatorClickHandler }">
9393
<div
9494
v-if="suggestions"
9595
:data-is-open="isOpen"
@@ -142,7 +142,7 @@
142142
v-bind="suggestionProps"
143143
>
144144
<template #item="itemSlotProps">
145-
<slot name="item" v-bind="itemSlotProps"/>
145+
<slot name="suggestion-item" v-bind="itemSlotProps"/>
146146
</template>
147147
</lib-suggestions>
148148
</slot>
@@ -174,6 +174,10 @@ const $slots = useSlots()
174174
const emits = defineEmits<{
175175
(e: "update:modelValue", val: T): void
176176
(e: "submit", val: T): void
177+
(e: "input", val: InputEvent): void
178+
(e: "keydown", val: KeyboardEvent): void
179+
(e: "blur", val: FocusEvent): void
180+
(e: "focus", val: FocusEvent): void
177181
}>()
178182
179183
/**
@@ -232,13 +236,14 @@ const suggestionsIndicatorClickHandler = () => {
232236
// inputWrapperEl.value?.blur()
233237
}
234238
}
235-
const handleInput = () => {
239+
const handleInput = (e: InputEvent) => {
236240
if (canEdit.value) {
237241
if (!props.restrictToSuggestions) {
238242
emits("update:modelValue", inputValue.value)
239243
} // else suggestions will handle updating modelvalue
240244
canOpen.value = true
241245
}
246+
emits("input", e)
242247
}
243248
244249
const handleKeydown = (e: KeyboardEvent) => {
@@ -251,16 +256,19 @@ const handleKeydown = (e: KeyboardEvent) => {
251256
if (values && e.key === "Escape" && !hasModifiers(e)) {
252257
canOpen.value = false
253258
}
259+
emits("keydown", e)
254260
}
255261
const handleBlur = (e: FocusEvent) => {
256262
if (props.suggestions) {
257263
// @ts-expect-error awaiting proper types for defineExpose
258264
suggestionsComponent.value?.inputBlurHandler?.(e)
259265
}
260266
canOpen.value = false
267+
emits("blur", e)
261268
}
262-
const handleFocus = () => {
269+
const handleFocus = (e: FocusEvent) => {
263270
canOpen.value = true
271+
emits("focus", e)
264272
}
265273
// todo emitting of value changes for isvalid
266274
const inputProps = computed(() => ({

0 commit comments

Comments
 (0)