Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Use boolean instead of map because composition always ends when switc…
…hing inputs
  • Loading branch information
muan committed Dec 20, 2018
commit 895f19bf5a43bc937df979c5e305423b9255d27a
7 changes: 3 additions & 4 deletions combobox-nav.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* @flow strict */

const compositionMap = new WeakMap()

export function install(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): void {
input.addEventListener('compositionstart', trackComposition)
input.addEventListener('compositionend', trackComposition)
Expand All @@ -17,13 +15,14 @@ export function uninstall(input: HTMLTextAreaElement | HTMLInputElement, list: H
list.removeEventListener('click', commitWithElement)
}

let isComposing = false
const ctrlBindings = !!navigator.userAgent.match(/Macintosh/)

function keyboardBindings(event: KeyboardEvent) {
if (event.shiftKey || event.metaKey || event.altKey) return
const input = event.currentTarget
if (!(input instanceof HTMLTextAreaElement || input instanceof HTMLInputElement)) return
if (compositionMap.get(input)) return
if (isComposing) return
const list = document.getElementById(input.getAttribute('aria-owns') || '')
if (!list) return

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

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