refactor(input): improve focus handling, alpha39 fixes

This commit is contained in:
Adam Bradley
2015-10-08 15:50:27 -05:00
parent 52bcc24901
commit b9ae06d442
11 changed files with 329 additions and 322 deletions

View File

@@ -176,8 +176,12 @@ export function hasPointerMoved(threshold, startCoord, endCoord) {
(Math.abs(startCoord.x - endCoord.x) > threshold || Math.abs(startCoord.y - endCoord.y) > threshold);
}
export function isActive(ele) {
return !!(ele && (document.activeElement === ele));
}
export function hasFocus(ele) {
return !!(ele && (document.activeElement === ele.nativeElement || document.activeElement === ele));
return isActive(ele) && (ele.parentElement.querySelector(':focus') === ele);
}
export function isTextInput(ele) {

View File

@@ -1,43 +0,0 @@
import {raf, ready} from './dom'
/* Focus Outline
* --------------------------------------------------
* When a keydown event happens, from a tab key, then the
* 'key-input' class is added to the body element so focusable
* elements have an outline. On a mousedown or touchstart
* event then the 'key-input' class is removed.
*/
let isKeyInputEnabled = false
function keyDown(ev) {
if (!isKeyInputEnabled && ev.keyCode == 9) {
isKeyInputEnabled = true
raf(enableKeyInput)
}
}
function enableKeyInput() {
document.body.classList[isKeyInputEnabled ? 'add' : 'remove']('key-input')
if (isKeyInputEnabled) {
document.addEventListener('mousedown', pointerDown)
document.addEventListener('touchstart', pointerDown)
} else {
document.removeEventListener('mousedown', pointerDown)
document.removeEventListener('touchstart', pointerDown)
}
}
function pointerDown() {
isKeyInputEnabled = false
raf(enableKeyInput)
}
ready().then(function() {
document.addEventListener('keydown', keyDown)
})