Skip to content

Commit 895f19b

Browse files
committed
Use boolean instead of map because composition always ends when switching inputs
1 parent 3df86d6 commit 895f19b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

combobox-nav.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* @flow strict */
22

3-
const compositionMap = new WeakMap()
4-
53
export function install(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): void {
64
input.addEventListener('compositionstart', trackComposition)
75
input.addEventListener('compositionend', trackComposition)
@@ -17,13 +15,14 @@ export function uninstall(input: HTMLTextAreaElement | HTMLInputElement, list: H
1715
list.removeEventListener('click', commitWithElement)
1816
}
1917

18+
let isComposing = false
2019
const ctrlBindings = !!navigator.userAgent.match(/Macintosh/)
2120

2221
function keyboardBindings(event: KeyboardEvent) {
2322
if (event.shiftKey || event.metaKey || event.altKey) return
2423
const input = event.currentTarget
2524
if (!(input instanceof HTMLTextAreaElement || input instanceof HTMLInputElement)) return
26-
if (compositionMap.get(input)) return
25+
if (isComposing) return
2726
const list = document.getElementById(input.getAttribute('aria-owns') || '')
2827
if (!list) return
2928

@@ -118,7 +117,7 @@ function clearSelection(list): void {
118117
function trackComposition(event: Event): void {
119118
const input = event.currentTarget
120119
if (!(input instanceof HTMLTextAreaElement || input instanceof HTMLInputElement)) return
121-
compositionMap.set(input, event.type === 'compositionstart')
120+
isComposing = event.type === 'compositionstart'
122121

123122
const list = document.getElementById(input.getAttribute('aria-owns') || '')
124123
if (!list) return

0 commit comments

Comments
 (0)