Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Apr 12, 2023
1 parent b85540a commit 763a295
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/@headlessui-react/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -821,12 +821,19 @@ function InputFn<
)

let isComposing = useRef(false)
let composedChangeEvent = useRef<React.ChangeEvent<HTMLInputElement> | null>(null)
let handleCompositionStart = useEvent(() => {
isComposing.current = true
})
let handleCompositionEnd = useEvent(() => {
setTimeout(() => {
isComposing.current = false

if (composedChangeEvent.current) {
actions.openCombobox()
onChange?.(composedChangeEvent.current)
composedChangeEvent.current = null
}
})
})

Expand Down Expand Up @@ -953,7 +960,10 @@ function InputFn<
})

let handleChange = useEvent((event: React.ChangeEvent<HTMLInputElement>) => {
if (isComposing.current) return
if (isComposing.current) {
composedChangeEvent.current = event
return
}
actions.openCombobox()
onChange?.(event)
})
Expand Down
12 changes: 11 additions & 1 deletion packages/@headlessui-vue/src/components/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,19 @@ export let ComboboxInput = defineComponent({
})

let isComposing = ref(false)
let composedChangeEvent = ref<(Event & { target: HTMLInputElement }) | null>(null)
function handleCompositionstart() {
isComposing.value = true
}
function handleCompositionend() {
setTimeout(() => {
isComposing.value = false

if (composedChangeEvent.value) {
api.openCombobox()
emit('change', composedChangeEvent.value)
composedChangeEvent.value = null
}
})
}

Expand Down Expand Up @@ -891,7 +898,10 @@ export let ComboboxInput = defineComponent({
}

function handleInput(event: Event & { target: HTMLInputElement }) {
if (isComposing.value) return
if (isComposing.value) {
composedChangeEvent.value = event
return
}
api.openCombobox()
emit('change', event)
}
Expand Down

0 comments on commit 763a295

Please sign in to comment.